基本属性
- contentEdgeInsets, titleEdgeInsets, imageEdgeInsets: 调整边距的三个属性.详细介绍
- reversesTitleShadowWhenHighlighted: 设置高亮时是否改变阴影.
- adjustsImageWhenHighlighted: 高亮状态下,image深一点.
- adjustsImageWhenDisabled: 被禁用状态,image浅一点.
- showsTouchWhenHighlighted: 触摸时候,会发光.
- tintColor: 所有的常用控件,都有tintColor属性。其中,UIView也有这个属性,可想而知继承UIView的控件也都有tintColor了。使用场景:当父视图更改了tintColor为red,那么它所有的一级子视图tintColor全部为red,除非你主动设置过子视图的tintColor。它再往下的子视图的tintColor则遵循直接父视图的tintColor 。
- buttonType: 按钮类型.
- currentTitle: 按钮当前的标题.(只读)
- currentTitleColor: 当前title颜色.(只读)
- currentTitleShadowColor:当前title阴影颜色.(只读)
- currentImage: 当前image.(只读)
- currentBackgroundImage:当前背景图片.(只读)
- currentAttributedTitle:当前富文本.(只读)
- titleLabel:存放标题的label.(只读)
- imageView:存放图片的imageView.(只读)
方法
//设置某种状态下的标题
- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state;
//设置某种状态下标题的颜色
- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state ;
//设置title在不同状态下的阴影颜色
- (void)setTitleShadowColor:(nullable UIColor *)color forState:(UIControlState)state;
//设置图片
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;
//设置背景图片
- (void)setBackgroundImage:(nullable UIImage *)image forState:(UIControlState)state;
//设置富文本
- (void)setAttributedTitle:(nullable NSAttributedString *)title forState:(UIControlState)state;
//根据不同状态获取相关属性.
- (nullable NSString *)titleForState:(UIControlState)state;
- (nullable UIColor *)titleColorForState:(UIControlState)state;
- (nullable UIColor *)titleShadowColorForState:(UIControlState)state;
- (nullable UIImage *)imageForState:(UIControlState)state;
- (nullable UIImage *)backgroundImageForState:(UIControlState)state;
- (nullable NSAttributedString *)attributedTitleForState:(UIControlState)state;
//可以自定义绘制
- (CGRect)backgroundRectForBounds:(CGRect)bounds;
- (CGRect)contentRectForBounds:(CGRect)bounds;
- (CGRect)titleRectForContentRect:(CGRect)contentRect;
- (CGRect)imageRectForContentRect:(CGRect)contentRect;