ui--button

来源:互联网 发布:淘宝上卖食品需要什么 编辑:程序博客网 时间:2024/05/21 15:45

【UIButton】

//UIButton是一个视图类,继承自UIControl 间接继承自UIView

//凡是UIControl子类可以接收触发事件

//UIButton用于创建一个按钮,添加点击事件

开发中注意的事情:把我们的button 尽量写的够大,可以看起来下,但事实上一定要够大.

常见的三种状态

UIControlStateNormal 正常状态

UIControlStateHighlighted 高亮状态


UIControlStateSelected 选中状态(设置btn.selected)//大部分用在同意协议和不同意协议 讲课代码有 btn.selected=yes,就是被选中状态

//iOS9.0以后❤️加了一个特性,

uiControlStateFocused//聚焦状态(应该和3d touch有关)


常用方法

//设置title

- (void)setTitle:(NSString *)title forState:(UIControlState)state;

//设置title的颜色

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;

//设置前景图  用的是填充方式的第二种

- (void)setImage:(UIImage *)image forState:(UIControlState)state; 

//设置背景图片

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;

//给button添加方法

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

//间距

btn.contentEdgeinsets = uiedgeinsetsmake();//按钮整体内容四周间距

btn.titleedgeinsets=同上//标题四周间距

//图片四周间距

btn.imageedgeinsets=tongshang

@property(nullable, nonatomic,readonly,strong) NSString *currentTitle;             //当前标题

@property(nonatomic,readonly,strong) UIColor  *currentTitleColor;                  //当前标题颜色

@property(nullable, nonatomic,readonly,strong) UIColor  *currentTitleShadowColor;  //当前标题阴影颜色

@property(nullable, nonatomic,readonly,strong) UIImage  *currentImage;             //当前图片

@property(nullable, nonatomic,readonly,strong) UIImage  *currentBackgroundImage;   //当前背景图片

@property(nullable, nonatomic,readonly,strong) NSAttributedString *currentAttributedTitle NS_AVAILABLE_IOS(6_0);  //当前富文本标题


@property(nullable, nonatomic,readonly,strong) UILabel     *titleLabel NS_AVAILABLE_IOS(3_0); //当前标题UILabel

@property(nullable, nonatomic,readonly,strong) UIImageView *imageView  NS_AVAILABLE_IOS(3_0); //当前图片UIImageView


//开发中经常用到2个按钮如果点中一个另一个就取消选中



0 0
原创粉丝点击