1、Label
(1)声明
@property(weak,nonatomic)IBOutlet UILabel *label1;//IBOutlet关联控件,storyboard中按住ctrl键拖线关联
也可以直接创建:
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(40, 240, 200, 20)];
(2)定义属性
label1.frame = CGRectMake(40, 240, 200, 20); //坐标大小(X轴,Y轴,宽,高)label1.font = [UIFont systemFontOfSize:13];//字体尺寸label1.textColor = [UIColor blackColor];//字体颜色:黑色label1.backgroundColor = [UIColor redColor];//背景颜色label1.textAlignment = NSTextAlignmentLeft;//字体对齐方式:左对齐label1.text = @\"李小伟牛逼!\";//文本内容//下面两行设置UILabel多行显示label1.lineBreakMode = NSLineBreakByCharWrapping;label1.numberOfLines = 0;[label1 sizeToFit];//设置大小自适应label1.layer.borderWidth = 1.0f;//设置边框label1.layer.cornerRadius = 4.0f;//设置圆角[self.view addSubview:label1];//添加到视图
2、Textfile
(1)声明
@property(weak,nonatomic)IBOutlet UItextfile *txt1;
也可以直接创建:
UITextField *txt1 = [[UITextField alloc]initWithFrame:CGRectMake(40, 200, 200, 20)];
(2)定义属性
txt1.textColor =[UIColor blackColor];//输入的字体颜色txt1.backgroundColor = [UIColor clearColor];//输入框文本背景颜色txt1.keyboardType = UIKeyboardTypeNumberPad;//键盘格式:数字键盘txt1.font = [UIFont systemFontOfSize:14];//输入的文本尺寸txt1.textAlignment = NSTextAlignmentLeft;//输入文本内容对齐方式:左对齐txt1.placeholder = @\"请输入\";//占位符,输入框提示文字,默认为灰色txt1.layer.borderWidth = 1.0f;//设置边框txt1.layer.cornerRadius = 4.0f;//设置圆角[self.view addSubview:txt1];//添加到视图
3、Button
(1)声明
@property(weak,nonatomic)IBOutlet UIButton *btn1;
也可以直接创建:
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
(2)定义属性
btn1 = [[UIButton alloc] initWithFrame:CGRectMake(16, 62, 10, 19)];//坐标大小//CGRect rect1 = CGRectMake(16, 62, 10, 19);//btn1.frame = rect1;btn1.tag = 10001;//按钮唯一标识[btn1 setImage:[UIImage imageNamed:@\"图片名称\"] forState:(UIControlStateNormal)];//按钮背景图片[btn1 setTitle:@\"按钮\" forState:UIControlStateNormal];//按钮文本btn1.titleLabel.font = [UIFont systemFontOfSize:16];//文本尺寸[btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];//文本颜色btn1.backgroundColor = [UIColor redColor];//按钮背景颜色btn1.layer.cornerRadius = 4.0f;//按钮圆角btn1.layer.masksToBounds = YES;//对button内lab约束btn1.layer.borderColor = [[UIColor redColor]CGColor];//按钮边框颜色btn1.layer.borderWidth = 1.0;//按钮边框宽度[btn1 addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];//创建触发函数,函数名为login[self.view addSubview:btn1];//添加到视图
4、image
UIImageView *image1 = [[UIImageView alloc]init];//创建视图对象image1.frame = CGRectMake(83, 133, 216, 36);//设置图片尺寸image1.center = self.view.center;//让图片在中间位置显示image1.image = [UIImage imageNamed:@\"logo\"];//加载图片[self.view addSubview:image1];//添加到视图