天天看点

UIButton头文件学习

UIButtonType枚举:

    UIButtonTypeCustom                               自定义按钮类型

    UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),   系统按钮类型

    UIButtonTypeDetailDisclosure,                    蓝色小箭头按钮              

    UIButtonTypeInfoLight,                           亮色感叹号                        

    UIButtonTypeInfoDark,                            暗色感叹号

    UIButtonTypeContactAdd,                          十字加号按钮

    UIButtonTypeRoundedRect = UIButtonTypeSystem,    已过时,使用UIButtonTypeSystem替代

UIButton继承体系:

          UIButton -> UIControl ->UIView

常用的属性:

@property(nonatomic)          UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR;   按钮内容间距

@property(nonatomic)          UIEdgeInsets titleEdgeInsets;                            按钮标题间距   

@property(nonatomic)          BOOL         reversesTitleShadowWhenHighlighted;         标题的阴影改变时,按钮是否高亮显示。默认为NO

@property(nonatomic)          UIEdgeInsets imageEdgeInsets;                            按钮图片间距

@property(nonatomic)          BOOL         adjustsImageWhenHighlighted;                按钮高亮的情况下,图像的颜色是否要加深一点。默认是YES

@property(nonatomic)          BOOL         adjustsImageWhenDisabled;                   按钮禁用的情况下,图像的颜色是否要加深一点。默认是YES

@property(nonatomic)          BOOL         showsTouchWhenHighlighted __TVOS_PROHIBITED;按下按钮是否会发光。默认是NO

设置按钮不同状态下外观的一系列方法(set):

- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state;                     // default is nil. title is assumed to be single line

- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default if nil. use opaque white

- (void)setTitleShadowColor:(nullable UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil. use 50% black

- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;                      // default is nil. should be same size if different for different states

- (void)setBackgroundImage:(nullable UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil

- (void)setAttributedTitle:(nullable NSAttributedString *)title forState:(UIControlState)state NS_AVAILABLE_IOS(6_0); // default is nil. title is assumed to be single line

获取按钮不同状态下外观的一系列方法(get)

- (nullable NSString *)titleForState:(UIControlState)state;          // these getters only take a single state value

- (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 NS_AVAILABLE_IOS(6_0);

获取按钮当前状态下的一系列属性(get)

@property(nullable, nonatomic,readonly,strong) NSString *currentTitle;             // normal/highlighted/selected/disabled. can return nil

@property(nonatomic,readonly,strong) UIColor  *currentTitleColor;        // normal/highlighted/selected/disabled. always returns non-nil. default is white(1,1)

@property(nullable, nonatomic,readonly,strong) UIColor  *currentTitleShadowColor;  // normal/highlighted/selected/disabled.

@property(nullable, nonatomic,readonly,strong) UIImage  *currentImage;             // normal/highlighted/selected/disabled. can return nil

@property(nullable, nonatomic,readonly,strong) UIImage  *currentBackgroundImage;   // normal/highlighted/selected/disabled. can return nil

@property(nullable, nonatomic,readonly,strong) NSAttributedString *currentAttributedTitle NS_AVAILABLE_IOS(6_0);  // normal/highlighted/selected/disabled. can return nil