iOS. UIButton 常用方法
2016-03-06 21:24
645 查看
UIButton 常用的设置
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; /** UIControlStateNormal = 0, 默认 UIControlStateHighlighted = 1 << 0, 高亮 UIControlStateDisabled = 1 << 1, UIControlStateSelected = 1 << 2, 编辑 */ /** //设置对应状态的标题内容default is nil. title is assumed to be single line - (void)setTitle:(NSString *)title forState:(UIControlState)state; //设置对应状态的标题颜色 - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state; //设置对应状态的标题阴影颜色 - (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state; //设置对应状态的按钮的图片 - (void)setImage:(UIImage *)image forState:(UIControlState)state; //设置对应状态的按钮背景图片 - (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state; */ UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom]; button1.frame = CGRectMake(40, 40, 60, 60); [button1 setImage:[UIImage imageNamed:@"Off"] forState:UIControlStateNormal]; [button1 setImage:[UIImage imageNamed:@"On"] forState:UIControlStateHighlighted]; [button1 addTarget:self action:@selector(button1:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button1]; /** UIControlEventTouchDown 单点触摸按下事件:用户点触屏幕,或者又有新手指落下的时候。 UIControlEventTouchDownRepeat 多点触摸按下事件,点触计数大于1:用户按下第二、三、或第四根手指的时候。 UIControlEventTouchDragInside 当一次触摸在控件窗口内拖动时。 UIControlEventTouchDragOutside 当一次触摸在控件窗口之外拖动时。 UIControlEventTouchDragEnter 当一次触摸从控件窗口之外拖动到内部时。 UIControlEventTouchDragExit 当一次触摸从控件窗口内部拖动到外部时。 UIControlEventTouchUpInside 所有在控件之内触摸抬起事件。 UIControlEventTouchUpOutside 所有在控件之外触摸抬起事件(点触必须开始与控件内部才会发送通知)。 UIControlEventTouchCancel 所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者被上锁或者电话呼叫打断。 UIControlEventTouchChanged 当控件的值发生改变时,发送通知。用于滑块、分段控件、以及其他取值的控件。你可以配置滑块控件何时发送通知在滑块被放下时发送,或者在被拖动时发送。 UIControlEventEditingDidBegin 当文本控件中开始编辑时发送通知。 UIControlEventEditingChanged 当文本控件中的文本被改变时发送通知。 UIControlEventEditingDidEnd 当文本控件中编辑结束时发送通知。 UIControlEventEditingDidOnExit 当文本控件内通过按下回车键(或等价行为)结束编辑时,发送通知。 UIControlEventAlltouchEvents 通知所有触摸事件。 UIControlEventAllEditingEvents 通知所有关于文本编辑的事件。 UIControlEventAllEvents 通知所有事件。 */ UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom]; button2.frame = CGRectMake(40, 120, 60, 60); [button2 setImage:[UIImage imageNamed:@"Off"] forState:UIControlStateNormal]; [button2 setImage:[UIImage imageNamed:@"On"] forState:UIControlStateSelected]; [button2 addTarget:self action:@selector(button2:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button2]; } - (void)button1:(UIButton *)sender { NSLog(@"高亮"); } - (void)button2:(UIButton *)sender { sender.selected = !sender.selected; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
一个高亮 效果
一个编辑效果
相关文章推荐
- iOS UI基础学习历程
- UIButton
- 博弈论(二):Sprague-Grundy函数
- juery实现贪吃蛇的游戏
- objc_property_attribute_t 的value和name
- easyUI confirm消息框的OK和cancel按钮的修改
- (java)Increasing Triplet Subsequence
- 使用Arduino读取噪声传感器分贝值
- 批判性思维——Asking The Right Questions
- 骨骼算法,仿生中的外观
- View Programming Guide for iOS 学习笔记_3
- Android Volley完全解析(三),定制自己的Request
- 关于UITableView 的一些重用技术注意点
- hdu1509 Windows Message Queue(优先队列水)
- leetcode52 N-Queens II
- (java)Unique Binary Search Trees
- POJ 3458 Colour Sequence
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
- StringBuffer和StringBuilder存在的作用是什么
- blade and soul pvp guide