UIButton - 使用详解
来源:互联网 发布:ted演讲软件下载 编辑:程序博客网 时间:2024/05/17 04:32
UIButton按钮是IOS开发中最常用的控件,作为IOS基础学习教程知识 ,初学者需要了解其基本定义和常用设置,以便在开发在熟练运用。
第一、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 is YES. if NO, ignores touch events and subclasses may draw differently @property(nonatomic,getter=isSelected)BOOL selected; // default is NO 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:nil forControlEvents:UIControlEventTouchUpInside];
第九、 设置按钮内部图片间距和标题间距
UIEdgeInsets insets; // 设置按钮内部图片间距 insets.top = insets.bottom = insets.right = insets.left = 10; bt.contentEdgeInsets = insets; bt.titleEdgeInsets = insets; // 标题间距
PS - 设置圆角型的
UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom]; signBtn.frame = CGRectMake(0, 0, 80, 40); [signBtn.layer setMasksToBounds:YES]; [signBtn.layer setCornerRadius:10.0];//设置矩形四个圆角半径 [signBtn.layer setBorderWidth:1.0];<span style="white-space:pre"></span>//边框宽度 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 }); [signBtn.layer setBorderColor:colorref];//边框颜色
0 0
- UIButton使用详解
- IOS UIButton使用详解
- UIButton使用详解
- UIButton使用详解
- UIButton使用详解
- IOS UIButton使用详解
- IOS UIButton使用详解
- IOS UIButton使用详解
- UIButton使用详解
- UIButton - 使用详解
- iOS 之UIButton 使用详解
- Swift UIButton的使用详解
- UIButton 详解
- UIButton 详解
- UIButton 详解
- UIButton 详解
- UIButton详解
- UIButton详解
- 安卓日记——蓝牙串口返回数据分段问题
- C++ primer读书笔记--第二章 变量和基本类型
- [leetcode] Pow(x, n)
- struts2标签,整合其他大神博客
- 华为OJ--小明的筷子
- UIButton - 使用详解
- HDU 1232 畅通公程
- Ubuntu 14.04 文件服务器--samba的安装和配置
- 第4周项目5:用递归方法求解-求n的阶乘
- hdu1028 poj1221 母函数 整数的拆分
- jQuery学习笔记(四)
- Android官方开发文档Training系列课程中文版:支持不同的设备之支持不同的屏幕
- ID为0和ID为1的进程
- 第二周项目4:穷举法解决组合问题(5)