UIView中UIButton的常用方法
来源:互联网 发布:135端口可以关闭吗 编辑:程序博客网 时间:2024/05/16 05:26
UIButton
UIButton的定义
UIButton *button=[[UIButton buttonWithType:(UIButtonType);
能够定义的button类型有以下6种,
typedef enum {
UIButtonTypeCustom = 0, 自定义风格
UIButtonTypeRoundedRect, 圆角矩形
UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用
UIButtonTypeInfoLight, 亮色感叹号
UIButtonTypeInfoDark, 暗色感叹号
UIButtonTypeContactAdd, 十字加号按钮
} UIButtonType;
frame
button1.frame = CGRectMake(20, 20, 280, 40);
[button setFrame:CGRectMake(20,20,50,50)];
button背景色
button1.backgroundColor = [UIColor clearColor];
[button setBackgroundColor:[UIColor blueColor]];
state状态
forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现
enum {
UIControlStateNormal = 0, 常规状态显现
UIControlStateHighlighted = 1 << 0, 高亮状态显现
UIControlStateDisabled = 1 << 1, 禁用的状态才会显现
UIControlStateSelected = 1 << 2, 选中状态
UIControlStateApplication = 0x00FF0000, 当应用程序标志时
UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管
};
@property(nonatomic,getter=isEnabled)BOOL enabled; // default isYES. if NO, ignores touch events and subclasses may draw differently
@property(nonatomic,getter=isSelected)BOOL selected; // default isNO may be used by some subclasses or by application
@property(nonatomic,getter=isHighlighted)BOOL highlighted;
设置button填充图片和背景图片
[buttonsetImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];
[buttonsetBackgroundImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];
设置button标题和标题颜色
[button1 setTitle:@"点击"forState:UIControlStateNormal];
[buttonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];
设置按钮按下会发光
button.showsTouchWhenHighlighted=NO;
添加或删除事件处理
[button1 addTarget:self action:@selector(butClick:)forControlEvents:UIControlEventTouchUpInside];
[btn removeTarget:nil action:nilforControlEvents:UIControlEventTouchUpInside];
设置按钮内部图片间距和标题间距
UIEdgeInsets insets; // 设置按钮内部图片间距
insets.top = insets.bottom = insets.right = insets.left = 10;
bt.contentEdgeInsets = insets;
bt.titleEdgeInsets = insets; // 标题间距
- UIView中UIButton的常用方法
- UIButton 的 常用方法
- 总结 UIView常用属性 与方法UIButton UIlabel UIControl
- iOS设置圆形(圆角)UIView、UIButton的简单方法
- 一些 UIView 中管理 Subview 常用的方法
- 一些 UIView 中管理 Subview 常用的方法
- 一些 UIView 中管理 Subview 常用的方法
- 一些 UIView 中管理 Subview 常用的方法
- 一些 UIView 中管理 Subview 常用的方法
- 一些UIView中管理Subview常用的方法
- 一些 UIView 中管理 Subview 常用的方法
- UIButton和UIView的区别
- UIView UILabel UITextField UIButton UIImageView 常用属性
- IOS--UIButton的常用属性和方法
- UIButton的一些常用方法设置
- UIView 中常见的方法
- UIButton常用方法
- iOS. UIButton 常用方法
- Markdown语法效果展示
- hbase shell示例
- Python实现人工神经网络(反向传播算法)
- linux学习笔记入门之用户及文件权限
- 基于S52单片机的温度测量与报警装置
- UIView中UIButton的常用方法
- ch3 硬盘与存储设备
- JAVA多线程
- NYOJ 448 寻找最大数
- An Introduction to WebDriver Using the JavaScript Bindings
- 什么是jQuery?
- Sublime Text3使用总结
- tomcat
- Eclipse闪退/打不开/无法启动/一闪而过