UI基本视图控制
给父视图添加背景图片
UIImageView *imgView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beijing"]];
//@""里面的为文件名,这样写需要将背景图片拖入工程中才可以
imgView.frame=self.view.bounds;
//自动适应屏幕大小
imgView.autoresizingMask=UIViewAutoresizingFlexibleWidth;
//给父视图添加背景图片
[self.view insertSubview:imgView atIndex:0];
子视图添加到指定位置
self.headView=[[UIImageView alloc] initWithFrame:CGRectMake(45, 100, 30, 30)];
//添加文件名为phoneIcon@2x的图片
[self.headView setImage:[UIImage imageNamed:@"phoneIcon@2x"]];
[self.view addSubview:self.headView];
添加按钮
self.buttonRegister=[UIButton buttonWithType:UIButtonTypeRoundedRect];
//确定按钮在父视图中的位置
self.buttonRegister.frame=CGRectMake(45, 300, 320, 50);
//设置按钮的名称
[self.buttonRegister setTitle:@"注册" forState:UIControlStateNormal];
//按钮的倒圆角,值越大,圆角的幅度越大
self.buttonRegister.layer.cornerRadius=10;
//设置按钮的背景色
self.buttonRegister.backgroundColor=[UIColor whiteColor];
//设置按钮里面字体的大小和宽度
_buttonRegister.titleLabel.font=[UIFont systemFontOfSize:25 weight:10];
//配置按钮里面字体的颜色
[self.buttonRegister setTitleColor:[UIColor colorWithRed:0.176 green:0.627 blue:0.588 alpha:1] forState:UIControlStateNormal];
//添加按钮视图到父视图
[self.view addSubview:self.buttonRegister];
触碰函数
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//调用隐藏键盘函数
[self hidekeyBoard];
}
/**
* 隐藏键盘函数
*/
-(void)hidekeyBoard
{
//判断是否为第一响应
if ([self.textName1 isFirstResponder]||[self.textName2 isFirstResponder])
{
//失去第一响应
[self.textName1 resignFirstResponder];
[self.textName2 resignFirstResponder];
}
}