UI控件方法、属性的总结
2015-11-02 08:58
417 查看
UILabel
label.backgroundColor=
[UIColorwhiteColor];设置label背景颜色
label.text
=
@“吃饭是为了活着,但活着就为了吃饭吗”;设置label文本内容
label.textColor
= [UIColor
blackColor];// 文本字体颜色
label.textAlignment
=
NSTextAlignmentCenter;//文本对齐方式(横)
label.font
= [UIFont
systemFontOfSize:30];//设置字体大小和样式
label.shadowOffset = CGSizeMake(4.0, 4.0); //设置字体偏移量
label.shadowColor
= [UIColor
redColor];//设置字体阴影颜色
label.layer.borderWidth = 3; //设置label边框宽度
label.layer.borderColor = [UIColor redColor].CGColor;边框颜色
label.layer.cornerRadius = 8;// 设置圆角
label.layer.masksToBounds = NO; //边框随着圆弧变动
label.clipsToBounds = YES;
// 设置背景颜色可以用自定义颜色
self.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
UIButton
遇到新类看什么?
1.首先看该类继承于哪个类?
2.看该类是否有自己的初始化方法
UIButton继承于UIControl: UIControl是一种于用户交互的类
button[b]核心方法:[/b]
[abutton
addTarget:self
action:@selector(buttonAction)
forControlEvents:UIControlEventTouchUpInside];
- (void)buttonAction{...}
参数1:目标:Target
设置执行方法的目标对象
参数2:行为:action
设置点击后触发的方法
参数3:时间类型:设置按钮点击时间类型
UIButton = [UIButton buttonWithType:UIButtonTypeCustom]; 初始化
button.frame = CGRectMake(0,0,0,0); 按钮的位置坐标
button.tag = 100; // 按钮的标记值
button.backgroundColor = [UIColor redColor]; 按钮背景颜色
// 按钮在某种状态下的标题
[button setTitle:@“确定” forState:
UIControlStateNormal];
// 按钮在某种状体下 标题的颜色
[button setTitleColor:[UIColor blackColor] forState:
UIControlStateNormal];
// 更改按钮标题的字体大小及样式
button.titleLabel.font = [UIFont systemFontOfSize:25];
[button.titleLabel
setFont:[UIFont
systemFontOfSize:30]];
// 设置按钮标题字体的偏移量
button.titleLabel.shadowOffset =
CGSizeMake(5.5,
5.5);
// 设置按钮标题的阴影颜色
[button
setTitleShadowColor:[UIColor
redColor] forState:UIControlStateNormal]
按钮也可以设置边框宽度、边框圆角、超过边框是否显示等属性,其方法与UILabel方法相同
UITextField
textField.backgroundColor // 背景颜色
textField.borderStyle // 输入框的外形样式
textField.placeholder // 提醒用户输入内容
textField.text // 输入框默认文本
textField.clearButtonMode // 快速清除按钮
textField.keyBoardType // 键盘样式
textField.secureTextEntry = yes; // 密文输入,隐藏输入信息,用于密码输入框
textField.clearsOnBeginEditing = yes; //开始编辑的时候清空输入框内容
textField.minimumFontSize = 3.0 // 设置最小收缩字号,在iOS6.0以后不用了
*****************************************************************************************************
textField.background = [UIImage imageNamed:@“照片名.jpg”]; 背景图片
// 输入框内容的字体大小及样式
textField.font = [UIFont fontWithName:@“Arial” size:20.0f];
textField.textColor = [UIColor redColor]; // 输入框内容字体颜色
UIImageView
// 初始化
UIImageView *imageView =[ [UIImageView alloc] initWithFrame:CGRectMake:(
0,
50, self.view.frame.size.width,
self.view.frame.size.height-100)];
// 设置图片
imageView.image = [UIImage imageNamed:@“图片名.jpg"];
// 图片也可以设置其他背景颜色
imageView.backgroundColor = [UIColor redColor];
// 图片展示的问题
imageView.contentMode =
UIViewContentModeScaleToFill, // 拉伸图片以适应屏幕
UIViewContentModeScaleAspectFit, // 显示图片原来大小
UIViewContentModeScaleAspectFill, // 布满整个屏幕,不做拉伸
如果父视图没有交互,那么父视图上得子视图也同样没有交互,在UI视图控件中,UILabel和UIImageView这两个控件默认是没有交互的,如果在这两个控件上添加需要交互的控件时,需要把这两个控件的交互打开
label.backgroundColor=
[UIColorwhiteColor];设置label背景颜色
label.text
=
@“吃饭是为了活着,但活着就为了吃饭吗”;设置label文本内容
label.textColor
= [UIColor
blackColor];// 文本字体颜色
label.textAlignment
=
NSTextAlignmentCenter;//文本对齐方式(横)
label.font
= [UIFont
systemFontOfSize:30];//设置字体大小和样式
label.shadowOffset = CGSizeMake(4.0, 4.0); //设置字体偏移量
label.shadowColor
= [UIColor
redColor];//设置字体阴影颜色
label.layer.borderWidth = 3; //设置label边框宽度
label.layer.borderColor = [UIColor redColor].CGColor;边框颜色
label.layer.cornerRadius = 8;// 设置圆角
label.layer.masksToBounds = NO; //边框随着圆弧变动
label.clipsToBounds = YES;
// 设置背景颜色可以用自定义颜色
self.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
UIButton
遇到新类看什么?
1.首先看该类继承于哪个类?
2.看该类是否有自己的初始化方法
UIButton继承于UIControl: UIControl是一种于用户交互的类
button[b]核心方法:[/b]
[abutton
addTarget:self
action:@selector(buttonAction)
forControlEvents:UIControlEventTouchUpInside];
- (void)buttonAction{...}
参数1:目标:Target
设置执行方法的目标对象
参数2:行为:action
设置点击后触发的方法
参数3:时间类型:设置按钮点击时间类型
UIButton = [UIButton buttonWithType:UIButtonTypeCustom]; 初始化
button.frame = CGRectMake(0,0,0,0); 按钮的位置坐标
button.tag = 100; // 按钮的标记值
button.backgroundColor = [UIColor redColor]; 按钮背景颜色
// 按钮在某种状态下的标题
[button setTitle:@“确定” forState:
UIControlStateNormal];
// 按钮在某种状体下 标题的颜色
[button setTitleColor:[UIColor blackColor] forState:
UIControlStateNormal];
// 更改按钮标题的字体大小及样式
button.titleLabel.font = [UIFont systemFontOfSize:25];
[button.titleLabel
setFont:[UIFont
systemFontOfSize:30]];
// 设置按钮标题字体的偏移量
button.titleLabel.shadowOffset =
CGSizeMake(5.5,
5.5);
// 设置按钮标题的阴影颜色
[button
setTitleShadowColor:[UIColor
redColor] forState:UIControlStateNormal]
按钮也可以设置边框宽度、边框圆角、超过边框是否显示等属性,其方法与UILabel方法相同
UITextField
textField.backgroundColor // 背景颜色
textField.borderStyle // 输入框的外形样式
textField.placeholder // 提醒用户输入内容
textField.text // 输入框默认文本
textField.clearButtonMode // 快速清除按钮
textField.keyBoardType // 键盘样式
textField.secureTextEntry = yes; // 密文输入,隐藏输入信息,用于密码输入框
textField.clearsOnBeginEditing = yes; //开始编辑的时候清空输入框内容
textField.minimumFontSize = 3.0 // 设置最小收缩字号,在iOS6.0以后不用了
*****************************************************************************************************
textField.background = [UIImage imageNamed:@“照片名.jpg”]; 背景图片
// 输入框内容的字体大小及样式
textField.font = [UIFont fontWithName:@“Arial” size:20.0f];
textField.textColor = [UIColor redColor]; // 输入框内容字体颜色
UIImageView
// 初始化
UIImageView *imageView =[ [UIImageView alloc] initWithFrame:CGRectMake:(
0,
50, self.view.frame.size.width,
self.view.frame.size.height-100)];
// 设置图片
imageView.image = [UIImage imageNamed:@“图片名.jpg"];
// 图片也可以设置其他背景颜色
imageView.backgroundColor = [UIColor redColor];
// 图片展示的问题
imageView.contentMode =
UIViewContentModeScaleToFill, // 拉伸图片以适应屏幕
UIViewContentModeScaleAspectFit, // 显示图片原来大小
UIViewContentModeScaleAspectFill, // 布满整个屏幕,不做拉伸
如果父视图没有交互,那么父视图上得子视图也同样没有交互,在UI视图控件中,UILabel和UIImageView这两个控件默认是没有交互的,如果在这两个控件上添加需要交互的控件时,需要把这两个控件的交互打开
相关文章推荐
- 关于UIview UIlabel Unbutton 的一些常用的属性方法(用以优化界面)
- getRequestDispatcher与sendRedirect
- JSP EL表达式 获得 request的GET/POST方法
- Android Api Demos登顶之路(113)Views-->SystemUiVisibility-->Game
- iOS对UIViewController生命周期和属性方法的解析
- C#分布式消息队列 EQueue 2.0 发布啦
- RPM包rpmbuild SPEC文件深度说明
- DuiLib介绍及其消息处理剖析 (new)
- DuiLib 消息机制剖析
- UICollectionView 实现的简易相册,可以缩放
- DLM - stackglue 层
- 阶段性理解include和require的区别
- 用系统图标创建UITabBarController
- UIAlertController
- iOS 9: UIStackView入门
- 优化UITableViewCell高度计算的那些事
- 最长递增子序列详解(longest increasing subsequence)
- AutoLayout深入浅出五[UITableView动态高度]
- 自定义UISlider的样式和滑块
- HDU 5531 Rebuild ——— 2015ACM-ICPC亚洲区长春站