UIButton
来源:互联网 发布:中国经济数据公布 编辑:程序博客网 时间:2024/04/25 04:02
- (void)viewDidLoad { [super viewDidLoad]; /** * 设计模式 :抽象工厂 -> 工厂模式 */ // UIButton : UIControl: UIView :UIResponder :NSObject // UIControl -> UIView带点击事件 按钮有一定的容错率 // UIButtonTypeInfoLight 信息按钮// UIButton *button1 = [UIButton buttonWithType:UIButtonTypeInfoDark]; UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom]; // 按钮的设置大多是调用方法,调用属性无效 // 设置标题 // 默认状态 UIControlStateNormal // 选中高亮状态 UIControlStateHighlighted // 选择状态 UIControlStateSelected [button1 setTitle:@"I am a button" forState:UIControlStateNormal]; [button1 setTitle:@"I am a touched button" forState:UIControlStateHighlighted]; // 设置顶部图片 [button1 setImage:[UIImage imageNamed:@"btn_prepage"] forState:UIControlStateNormal]; [button1 setImage:[UIImage imageNamed:@"btn_nextpage"] forState:UIControlStateHighlighted]; // 设置背景图片 [button1 setBackgroundImage:[UIImage imageNamed:@"btn_prepage"] forState:UIControlStateNormal]; // 正常状态下 [button1 setBackgroundImage:[UIImage imageNamed:@"btn_nextpage"] forState:UIControlStateHighlighted]; // 高亮状态下 [button1 setBackgroundImage:[UIImage imageNamed:@"btn_home"] forState:UIControlStateSelected]; // 选择状态下 // 设置文字颜色 [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; // 设置点击事件 /** forControlEvents - 触发按钮的条件 - 内部点击 action - 触发之后执行的方法 addTarget - 执行方法的对象 */ // 会自动将‘按钮’作为参数 [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; // 当点击btn内部时候,触发buttonAction方法 button1.tag = 101; button1.frame = CGRectMake(10, 30, 300, 50); button1.backgroundColor = [UIColor lightGrayColor]; UIButton *button2 = [UIButton buttonWithType:UIButtonTypeContactAdd]; button2.frame = CGRectMake(10, 100, 300, 30); button2.tag = 102; [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button1]; [self.view addSubview:button2];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - button Action- (void)buttonAction:(UIButton *)button { if (button.tag == 101) { // 通过判断按钮的tag来执行对应事件 NSLog(@"101 is clicked"); } else if (button.tag == 102){ NSLog(@"102 is clicked"); // 取到指定标示的button UIButton *button1 = (UIButton *)[self.view viewWithTag:101];// button1.selected = YES; //default is NO// 点击按钮是无法改变这个属性的,只有我们单独调用属性来进行设置 button1.selected = !button1.selected; } else { NSLog(@"error"); } }
0 0
- UIButton
- UIButton
- UIButton
- uibutton
- UIButton
- UIButton
- UIButton
- UIButton
- UIButton
- UIButton
- UIBUTTON
- UIButton
- UIButton
- UIButton
- UIBUTTON
- UIButton
- UIButton
- UIButton
- Tomcat总体架构(Tomcat源码解析系列二)
- 字典树
- 大浪淘沙,JSP终将死去
- 剑指Offer面试题39(Java版):二叉树的深度
- Ubuntu 安装搜狗输入法
- UIButton
- iOS开发~优雅的使用Xcode帮助文档及帮助系统
- squashfs
- 黑马程序员---Foundation -NSDictionary
- hdoj2845Beans【dp】
- Linux目录结构介绍
- 高并发访问数据库优化方法
- 创建Linux自定义服务
- 树莓派指示灯