UI基础篇-UIButton

1.创建按钮

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//按钮样式
UIButtonTypeCustom 用户自定义按钮
UIButtonTypeRoundedRect 圆角安妮
UIButtonTypeDetailDisclosure 更多信息按钮 >
UIButtonTypeInfoLight 高亮信息按钮i
UIButtonTypeInfoDark  暗色信息按钮i
UIButtonTypeContactAdd 加号按钮 +

2.常用方法

设置按钮额标题
-(void)setTitle:(NSString *)title forState:(UIControlState)state
//UIControlState
UIControlStateNormal 按钮一般状态
UIControlStateHighlighted 按钮被按下(高亮)状态
UIConstrolStateDisabled 按钮被禁用状态
//设置按钮颜色
-(void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
//设置按钮阴影颜色
-(void)setTitleShadowColor:(UIColor *)color forState(UIControlState)state;
//设置标题的颜色
-(void)setTintColor:(UIColor *)color;
//给按钮设置背景图片
-(void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;
//给按钮设置图片
-(void)setImage:(UIImage *)image forState:(UIControlState)state;

3.UIControl
作用:具有处理事件的控件的父类
UIButton和UIControl是继承关系

//添加一个事件
-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIConstrolEvents)controlEvents
//删除一个事件
-(void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIConstrolEvents)controlEvents

你可能感兴趣的:(UI基础篇-UIButton)