控件学习---UIButton--摘自培训资料
来源:互联网 发布:淘宝开店协议无法同意 编辑:程序博客网 时间:2024/05/29 13:44
·UIControl 是所有具有事件处理控件的父类
· 控件主要响应3种事件: 基于触摸的事件、基于值的事件、基于编辑的事件。
·常用事件: UIControlEventTouchUpInside 如按钮的点击事件、
·常用事件: UIControlEventTouchUpInside 如按钮的点击事件、
UIControlEventValueChanged 如进度条拖动。
常用方法:
//添加一个事件
- (void)addTarget:(id)target
action:(SEL)action
forControlEvents:(UIControlEvents)controlEvents
//删除一个事件
- (void)removeTarget:(id)
target
action:(SEL)action
forControlEvents:(UIControlEvents)controlEvents
事件处理:
UIButton按钮
UIButton按钮,主要用来响应用户点击事件。
· 常用属性
·buttonType 按钮显示样式类型
·titleLabel 按钮标题文本Label对象。
常用方法
//设置指定状态对应的标题文本
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
//设置指定状态对应的标题颜⾊
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
//设置指定状态对应的显⽰图⽚
- (void)setImage:(UIImage *)image forState:(UIControlState)state;
//设置指定状态对应的背景图⽚
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;
//为按钮添加事件
- (void)addTarget:(id)target action:(SEL)action forControlEvents:
(UIControlEvents)controlEvents;
UIButton状态
·button有很多种状态,不同的状态可以对应不同的按钮图片
UIButton状态:
UIControlStateNormal // 正常状态
UIControlStateHighlighted // 高亮状态
UIControlStateDisabled // 禁用状态
UIControlStateSelected // 选中状态
UIControlStateApplication //
UIControlStateReserved // 系统保留状态
UIButton 方法:
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
- (void)setTitleShadowColor:(UIColor *)color forState:
(UIControlState)state;
- (void)setImage:(UIImage *)image forState:(UIControlState)state;
- (void)setBackgroundImage:(UIImage *)image forState:
(UIControlState)state;
UIButton示例代码
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame =CGRectMake(20,40,100,30);
//设置平常状态下按钮的标题
[button setTitle:@"按钮"forState:UIControlStateNormal];
//设置⾼亮状态下按钮的标题
[button setTitle:@"按钮按下"forState:UIControlStateHighlighted];
//设置点击事件响应的⽅法
[button addTarget:selfaction:@selector(buttonAction)
forControlEvents:UIControlEventTouchUpInside];
//设置平常状态下标题的颜⾊
[button setTitleColor:[UIColorblackColor]forState:UIControlStateNormal];
//设置⾼亮状态下标题的颜⾊
[button setTitleColor:[UIColorredColor]forState:UIControlStateHighlighted];
//设置标题的字体
button.titleLabel.font= [UIFontsystemFontOfSize:14];
- 控件学习---UIButton--摘自培训资料
- 控件学习---UILabel--摘自培训资料
- 控件学习---UITextField---摘自培训资料
- 控件学习---UISlider---摘自培训资料
- 控件学习---UISegmentedControl---摘自培训资料
- 控件学习---UIActivityIndicatorView---摘自培训资料
- 控件学习---UIPageControl---摘自培训资料
- 学习ios控件之UIButton
- 控件学习---UIImageView---摘自培训文档
- UIButton 控件
- UIButton控件
- 【初学】UI控件学习笔记-UIButton按钮控件详细介绍
- IOS入门学习笔记(普通UI控件--UIButton)
- UIButton按钮控件
- UIButton按钮控件
- IOS 控件 UIButton button
- UIButton按钮控件
- UIButton按钮控件
- ThreadLocal源码解析
- java 获取当前时间的天、周、月、季度、半年度、年度开始和结束时间
- phpstorm设置编码 gbk gb2312 支持 asp
- NSDictionary及NSMutableDictionary
- Java读properties文件中文乱码问题的解决方法
- 控件学习---UIButton--摘自培训资料
- Spark源码阅读笔记之MetadataCleaner
- C语言第一天
- PC110101(3n+1问题)(3n+1 Problem)
- 一个JavaWeb项目中使用的部分技术
- HDU 1083 Courses(二分匹配匈牙利算法模板题啊)
- 第一个项目所学记录
- 黑马程序员--IO流之字符流
- HDU 2243 考研路茫茫――单词情结 (AC自动机 + 矩阵快速幂)