UIButton头文件学习

来源:互联网 发布:淘宝外围活动流量大吗 编辑:程序博客网 时间:2024/06/05 13:22

UIButtonType枚举:

    UIButtonTypeCustom                               自定义按钮类型

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

    UIButtonTypeDetailDisclosure,                    蓝色小箭头按钮              

    UIButtonTypeInfoLight,                           亮色感叹号                        

    UIButtonTypeInfoDark,                            暗色感叹号

    UIButtonTypeContactAdd,                          十字加号按钮

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

UIButton继承体系:

          UIButton -> UIControl ->UIView

常用的属性:

@property(nonatomic)          UIEdgeInsets contentEdgeInsetsUI_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:(nullableNSString *)title forState:(UIControlState)state;                    // default is nil. title is assumed to be single line

- (void)setTitleColor:(nullableUIColor *)color forState:(UIControlState)stateUI_APPEARANCE_SELECTOR; // default if nil. use opaque white

- (void)setTitleShadowColor:(nullableUIColor *)color forState:(UIControlState)stateUI_APPEARANCE_SELECTOR; // default is nil. use 50% black

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

- (void)setBackgroundImage:(nullableUIImage *)image forState:(UIControlState)stateUI_APPEARANCE_SELECTOR; // default is nil

- (void)setAttributedTitle:(nullableNSAttributedString *)title forState:(UIControlState)stateNS_AVAILABLE_IOS(6_0);// default is nil. title is assumed to be single line


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

- (nullableNSString *)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)stateNS_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 *currentAttributedTitleNS_AVAILABLE_IOS(6_0); // normal/highlighted/selected/disabled. can return nil




0 0