标签:
normal(普通状态)
highlighted(高亮状态)
disabled(失效状态,不可用状态)
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
(void)setTitle:(NSString *)title forState:(UIControlState)state;
(void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
(void)setImage:(UIImage *)image forState:(UIControlState)state;
(void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;
btn.titleLabel.font = [UIFont systemFontOfSize:13];
(NSString *)titleForState:(UIControlState)state;
(UIColor *)titleColorForState:(UIControlState)state;
(UIImage *)imageForState:(UIControlState)state;
(UIImage *)backgroundImageForState:(UIControlState)state;
//自定义 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; //状态 setImage//图片 //设置按钮在不同状态下的背景图片(为了保证高亮状态下的图片正常显示,必须设置按钮的type为custom) setBackgroundImage//背景图片 setTitle//文字 setTitleColor//文字颜色 //监听按钮 //当UIControlEventTouchUpInside时,调用btn的buttonClick方法 [btn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
因为UIImage和UILabel不是继承UIControl,只有继承UIControl才能通过addTarget来监听事件
只能通过enabled = NO达到UIControlStateDisables状态,设置userInterationEnabled = NO,并不能让按钮达到这个状态
标签:
原文地址:http://www.cnblogs.com/HMJ-29/p/4758646.html