UIButton用法小结
来源:互联网 发布:缸中之脑悖论破解知乎 编辑:程序博客网 时间:2024/05/24 06:50
// 初始化按钮并设置类型UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];// 能够定义的UIButton类型有以下6种:// typedef enum {// UIButtonTypeCustom = 0, 自定义风格// UIButtonTypeRoundedRect, 圆角矩形// UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用// UIButtonTypeInfoLight, 亮色感叹号// UIButtonTypeInfoDark, 暗色感叹号// UIButtonTypeContactAdd, 十字加号按钮// } UIButtonType;// 设置按钮大小和位置btn.frame = CGRectMake(20, 360, 280, 45);// 设置按钮背景颜色btn.backgroundColor = [UIColor colorWithRed:254/255.0f green:254/255.0f blue:254/255.0f alpha:1.0f];// 设置按钮文字[btn setTitle:@"Normal" forState:UIControlStateNormal];[btn setTitle:@"Pressed" forState:UIControlStateHighlighted];// forState这个参数的作用是定义按钮的文字或图片在何种状态下才会显现,以下是几种状态:// enum {// UIControlStateNormal = 0, 常规状态显现// UIControlStateHighlighted = 1 << 0, 高亮状态显现// UIControlStateDisabled = 1 << 1, 禁用的状态才会显现// UIControlStateSelected = 1 << 2, 选中状态// UIControlStateApplication = 0x00FF0000, 当应用程序标志时// UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管他// };// 设置按钮文字颜色[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];// 设置按钮文字字体[btn.titleLabel setFont:[UIFont systemFontOfSize:17]];[btn.layer setMasksToBounds:YES];// 设置按钮四个圆角半径[btn.layer setCornerRadius:4.0];// 设置按钮边框宽度[btn.layer setBorderWidth:0.5];// 设置按钮边框颜色CGColorRef colorref = CGColorCreate(CGColorSpaceCreateDeviceRGB(),(CGFloat[]){168/255.0f, 168/255.0f, 168/255.0f, 1.0});[btn.layer setBorderColor:colorref];// 去除按钮在叠加视图中的按下延迟tableView.delaysContentTouches = NO;// 添加点击事件[btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];// 在视图中显示按钮[tableView addSubview:btn];// 按钮点击事件- (void)btnAction:(id)sender{ // do something}
0 0
- UIButton用法小结
- iOS开发系列之一 - UIButton 用法小结
- UIButton小结
- UIButton小结
- UIButton小结
- UIButton小结
- UIButton用法
- Iphone开发UIButton小结
- UI -- UIButton小结
- UIButton常用小结
- UIButton按钮用法
- IOS ----UIButton用法详解
- IOS ----UIButton用法详解
- UIButton的用法
- IOS ----UIButton用法详解
- UIButton的简单用法
- IOS UIButton用法详解
- UIButton基本用法
- JS抽奖二次方缓动测试
- 选择排序
- android 数据流量统计
- How to log in Spring with SLF4J and Logback
- C++中引用(&)的用法和应用实例
- UIButton用法小结
- JavaScript技巧续
- LA 4043 Ants 二分图完美匹配
- java基础 iterator
- 二十年目睹之怪状-言论自由
- session: 简单购物车
- 软件安装和配置
- 使用Code::Blocks编译NERvSDK的插件示例代码
- java中有没有引用传递?