iOS_UIButton 简单操作
2015-06-02 21:39
387 查看
UIButton 风格
typedef NS_ENUM(NSInteger, UIButtonType) { UIButtonTypeCustom = 0, // no button type UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), // standard system button UIButtonTypeDetailDisclosure, UIButtonTypeInfoLight, UIButtonTypeInfoDark, UIButtonTypeContactAdd, UIButtonTypeRoundedRect = UIButtonTypeSystem, // Deprecated, use UIButtonTypeSystem instead };
简单操作
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; button.tag = 100; // 给 Button 添加标记 在不同的方法中使用同一个控件 button.frame = CGRectMake(30, 170, 200, 40); [self.window addSubview:button]; // 设置按钮文字,需要设置状态 [button setTitle:@"按钮" forState:UIControlStateNormal]; // [button setTitle:@"Hello" forState:UIControlStateHighlighted]; [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; // 给字体设置颜色 button.showsTouchWhenHighlighted = YES; // 高亮 // 给button绑定事件 [button addTarget:self // 接受消息的对象 action:@selector(buttonAction:) // 发送的消息 forControlEvents:UIControlEventTouchUpInside]; // 触发的方式
Button 方法
- (void) buttonAction { NSLog(@"咔"); // 通过 tag ,从父类视图中获取button UIButton *btn = (UIButton *)[self.window viewWithTag:100]; [btn setTitle:@"点我" forState:UIControlStateNormal]; // 让 Button 失效 [btn removeTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; } - (void) buttonAction:(UIButton *)sender { sender.backgroundColor = [UIColor redColor]; }
相关文章推荐
- iOS按钮UIButton常用属性总结
- UIScrollView代理方法
- easyui换主题,并记录在cookie.以及cookie作用域介绍
- java 的builder模式——设计思想
- .net mvc4 从客户端中检测到有潜在危险的 Request.Form 值
- IIC(Inter-Integrated Circuit)总线协议浅谈
- iOS开发UI篇—UITableview控件简单介绍
- Android Call requires API level 19 (current min is 11)
- OpenCV学习笔记(四十七)——VideoWriter生成视频流highgui
- 自定义UITableViewCell 上的多个按钮点击事件处理
- iOS-学习笔记-UI-第一天
- 6.2 视图UIView及视图控制器(UIViewController)
- ajax阻塞UI线程
- HDU 2227 Find the nondecreasing subsequences(DP)
- Arduino--Helloworld!
- 多线程编程(一)之 block 与 dispatch quene
- request.getParameter() 获取中文乱码
- 循环结构中break、continue、return和exit的区别
- UIViewContentMode
- 猫猫学IOS(一)UI之Hello World与加法计算器