OC UI控件之UILable UIBUtton UITextFiled
2015-11-13 00:00
399 查看
摘要: 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];
//--------------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];
相关文章推荐
- jquey学习篇 第一篇
- [非凡程序员]倒计时 uiimage uiDatePicker NSDate
- UGUI学习笔记
- UIDatePicker和UIPickerView
- [非凡程序员]手写UIDatePicker和UIPickerView
- 手写UIDatePicker和UIPickerView
- NSOperationQueue线程池应用
- oc 自定义UITableViewCell
- dispatch queues GCD
- 修复Grub rescue模式并启动
- django QuerySet 查询条件
- NGUI学习(三)
- NGUI学习(二)
- 在UIScrollView中使用Autolayout布局
- [翻译]AKKA笔记 - ACTOR MESSAGING - REQUEST AND RESPONSE -3
- 限制UITextField的输入长度
- 如何更好地限制一个UITextField的输入长度
- UI基础知识 -- 容器视图控制器
- UITableViewStyle设置Group、Plain问题
- UI基础知识 -- 视图控制器继承的一些方法