UIButton的基本用法和事件
2016-04-08 17:21
435 查看
// // MyViewController.m // Demo3UIButton // // Created by spare on 16/4/8. // Copyright © 2016年 spare. All rights reserved. // #import "MyViewController.h" @interface MyViewController () @end @implementation MyViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; button.frame=CGRectMake(20, 20, 200, 40); // button.backgroundColor=[UIColor lightGrayColor]; [button setTitle:@"按键" forState:UIControlStateNormal]; [button setTitle:@"高亮" forState:UIControlStateHighlighted]; [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; //设置button的图片,设置Button的背景图片 [button setImage:[UIImage imageNamed:@"Play-btn"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"stop"] forState:UIControlStateHighlighted]; [button setBackgroundImage:[UIImage imageNamed:@"BTN"] forState:(UIControlStateNormal)]; //设置按钮高亮照片 [button setBackgroundImage:[UIImage imageNamed:@"BTN2"] forState:(UIControlStateHighlighted)]; //设置按钮失效照片 [button setBackgroundImage:[UIImage imageNamed:@"disable"] forState:(UIControlStateDisabled)]; //设置按钮暂停照片 [button setBackgroundImage:[UIImage imageNamed:@"stop"] forState:(UIControlStateSelected)]; //button.enabled=NO; [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } //事件方法的参数通常都是触发这个事件对象的类型 //事件方法的参数就是触发事件的对象 -(void)buttonClick:(UIButton *)sender{ CGRect frame=sender.frame; frame.size.height=80; sender.frame=frame; [sender setTitle:@"按键………………" forState:UIControlStateNormal]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
相关文章推荐
- easyui验证
- iOS _监听UITextField输入状态
- 2786: [JSOI]Word Query电子字典
- 1007. Maximum Subsequence Sum
- iOS开发学习之 - 深入学习UIButton(1)
- iOS UI绘制和布局基础解析
- JAVA---Unique Characters
- 模板模式 和 策略模式的区别, builder pattern构造者模式,BeanDefinitionBuilder
- iOS学习笔记10-UIView动画
- UIButton Custom
- 解决requirejs某文件加载超时问题
- iOS中自定义UITableViewCell的用法
- Android开源框架收集-UI效果(一)
- 【转帖】Service Discovery: 6 questions to 4 experts
- UI数据解析(Dom,Sax,Json)
- UIView 与 UIWindow的关系
- leetcode 51. N-Queens
- #5JAVA字符串StringBuffer 和StringBuilder和 String #
- 如何查找使用某变量的query
- 自定义UICollectionViewLayout(二) ----StackLayout&CircleLayout