UIbutton

一:初始化

UIButton的初始化一般使用其类方法,+ (id)buttonWithType:(UIButtonType)buttonType;

枚举类型

//用户自定义,无风格
    UIButtonTypeCustom = 0,  
    //系统默认风格                       
    UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), 
    
    UIButtonTypeDetailDisclosure,
    UIButtonTypeInfoLight,
    UIButtonTypeInfoDark,
    //创建+号按钮
    UIButtonTypeContactAdd,
    //废弃
    UIButtonTypeRoundedRect = UIButtonTypeSystem,
};

二属性设置

@property(nonatomic) UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR;
//这个属性设置button里内容的偏移量,包括title和image,可以用如下方法设置
btn.contentEdgeInsets=UIEdgeInsetsMake(20, 20, 0, 0);
 
@property(nonatomic) UIEdgeInsets titleEdgeInsets;
//这个属性设置标题的偏移量         
@property(nonatomic) BOOL reversesTitleShadowWhenHighlighted;
//按钮高亮时,是否改变阴影效果
@property(nonatomic) UIEdgeInsets imageEdgeInsets;
//图片的偏移量              
@property(nonatomic)BOOL  adjustsImageWhenHighlighted;
//设置图片的绘制是否高亮时变暗   
@property(nonatomic)BOOL  adjustsImageWhenDisabled;
//设置图片是否轻绘制当按钮禁用时
@property(nonatomic)BOOL showsTouchWhenHighlighted;
//设置是否显示手指印在按钮高亮的时候
@property(nonatomic,retain)   UIColor     *tintColor NS_AVAILABLE_IOS(5_0); 
//这个属性会作用于标题和图片,但是如果你是自定义风格的按钮,这个属性将不起任何作用,它只作用于系统的
@property(nonatomic,readonly) UIButtonType buttonType;
//设置button的风格
属性设置

三一些设置方法

set方法

四一些获取方法

- (NSString *)titleForState:(UIControlState)state;       
- (UIColor *)titleColorForState:(UIControlState)state;
- (UIColor *)titleShadowColorForState:(UIControlState)state;
- (UIImage *)imageForState:(UIControlState)state;
- (UIImage *)backgroundImageForState:(UIControlState)state;
- (NSAttributedString *)attributedTitleForState:(UIControlState)state NS_AVAILABLE_IOS(6_0);

只读属性

@property(nonatomic,readonly,retain) NSString *currentTitle;        
@property(nonatomic,readonly,retain) UIColor  *currentTitleColor;    
@property(nonatomic,readonly,retain) UIColor  *currentTitleShadowColor; 
@property(nonatomic,readonly,retain) UIImage  *currentImage; 
@property(nonatomic,readonly,retain) UIImage  *currentBackgroundImage; 
@property(nonatomic,readonly,retain) NSAttributedString *currentAttributedTitle NS_AVAILABLE_IOS(6_0); 

@property(nonatomic,readonly,retain) UILabel     *titleLabel NS_AVAILABLE_IOS(3_0);
@property(nonatomic,readonly,retain) UIImageView *imageView  NS_AVAILABLE_IOS(3_0);

btn最重要的触发事件由于其是继承的uicontrol,不描述

 

posted @ 2015-11-20 17:22  断尽流年  阅读(176)  评论(0编辑  收藏  举报