您的位置:首页 > 产品设计 > UI/UE

OC UI控件之UILable UIBUtton UITextFiled

2015-11-13 00:00 375 查看
摘要: UILable UIBUtton UITextFiled 的手写创建以及常用的设置方法

//--------------UILable-------------
//创建一个标签
UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(80, 40, 200,50)];
//给标签设置内容
lable.text = @"Hello World";

//给标签内容设置颜色
lable.textColor = [UIColor blackColor];

//给标签设置字体
lable.font = [UIFont fontWithName:@"Arial" size:20];

//给标签设置背景颜色
//lable.backgroundColor = [UIColor greenColor];
lable.backgroundColor = [UIColor colorWithRed:0.5 green:0.8 blue:0.5 alpha:0.5];

//给标签设置边框宽度
lable.layer.borderWidth = 10;

//给标签设置边框颜色
//lable.layer.borderColor = [UIColor orangeColor].CGColor;
lable.layer.borderColor = [UIColor colorWithWhite:0.1 alpha:0.3].CGColor;

//字体居中
lable.textAlignment = NSTextAlignmentCenter;

//设置字体:粗体,正常的是SystemFontOfSize
lable.layer.cornerRadius = 20;

//设置阴影
lable.layer.shadowColor=[UIColor blackColor].CGColor;
lable.layer.shadowOffset=CGSizeMake(10, 20);//阴影大小
lable.layer.shadowRadius=20;

//设置lable 的行数
lable.numberOfLines = 2;

//设置lable中文字是否可变,默认为YES;
lable.enabled = NO;

//设置高亮
lable.highlighted = YES;
lable.highlightedTextColor = [UIColor orangeColor];

//把标签添加到视图
[self.view addSubview:lable];

//--------------UITextFiled-------------
//设置一个文本框
UITextField *textFiled = [[UITextField alloc]initWithFrame:CGRectMake(80,100, 200, 50)];

//设置输入框边框样式
textFiled.borderStyle=UITextBorderStyleLine;

//设置输入框的加密显示
textFiled.secureTextEntry=YES;

//设置输入框的字体居中位置
textFiled.textAlignment=NSTextAlignmentCenter;

//当输入框没有内容时,水印提示placeholder 提示内容为password
textFiled.placeholder=@"提示";

//给文本框添加背景颜色
textFiled.backgroundColor = [UIColor colorWithRed:0.6 green:0 blue:0 alpha:0.2];

//将文本框添加到视图中
[self.view addSubview:textFiled];

//--------------UIButton-------------
//设置一个button
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(80, 200, 50, 50)];

//设置button内容
[button setTitle:@"click" forState:UIControlStateNormal];

//设置内容颜色
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//设置button背景颜色
button.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0 alpha:0.4];

//设置按钮背景图片
// [button setBackgroundImage:[UIImage imageNamed:@"0"] forState:UIControlStateNormal];

//设置按钮边框
[button.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
[button.layer setBorderWidth:1.0]; //边框宽度
[button.layer setBorderColor:[UIColor blueColor].CGColor];//边框颜色

//给button添加点击事件
[button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

//给button移除点击事件
// [button removeTarget:self action:@selector(<#selector#>) forControlEvents:<#(UIControlEvents)#>]

//将button添加到视图中
[self.view addSubview:button];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: