iOS组件之UIButton详解

引言

UIButton的类是一个UIControl子类(有关UIControl请参照《iOS组件之UIControl详解》),它实现了在触摸屏上的按钮。触摸一个按钮拦截事件和动作消息发送到目标对象时,它的挖掘。设定的目标和行动方法都继承自UIControl。这个类提供了方法来设置标题,图像,按钮等外观属性。通过使用set方法,你可以指定一个不同的外观为每个按钮状态。

目录

// 初始化 button 样式

+ (id)buttonWithType:(UIButtonType)buttonType;

// 每边(左,右,顶部和底部)可以有不同的值。使用UIEdgeInsetsMake功能设置图片和文字的位置(默认为UIEdgeInsetsZero)

UIEdgeInsets contentEdgeInsets; 

// 设置标题、图片的边缘值(默认UIEdgeInsetsZero)

UIEdgeInsets titleEdgeInsets;                

// 决定是否点击按钮会导致其发光

BOOL         reversesTitleShadowWhenHighlighted; 

// 图像插图或一开始就为每个边缘

UIEdgeInsets imageEdgeInsets;                

// 决定是否按钮时,突出显示图像的变化。

BOOL         adjustsImageWhenHighlighted;    

// 决定是否形象的变化时,该按钮被禁用

BOOL         adjustsImageWhenDisabled;       

// 决定是否点击按钮会导致其发光

BOOL         showsTouchWhenHighlighted;      

// 设置背景颜色(iOS 5.0)

UIColor     *tintColor;

// button样式(只读)

UIButtonType buttonType;

// 设置某个状态下的title

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

// 设置某个状态下的title颜色

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

// 设置某个状态下的阴影颜色

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

// 设置某个状态下的图片

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

// 设置某个状态下的背景图片

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

// 设置某个状态下的title属性(iOS 6.0)

- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state; 

// 返回一个按钮的状态中使用的字体内容。

- (NSString *)titleForState:(UIControlState)state;

// 返回一个按钮的状态中使用的字体颜色。

- (UIColor *)titleColorForState:(UIControlState)state;

// 返回一个按钮的状态中使用的阴影颜色。

- (UIColor *)titleShadowColorForState:(UIControlState)state;

// 返回一个按钮的状态中使用的图像。

- (UIImage *)imageForState:(UIControlState)state;

// 返回一个按钮的状态中使用的背景图像

- (UIImage *)backgroundImageForState:(UIControlState)state;

// 返回一个按钮的状态中使用的内容属性(iOS 6.0)

- (NSAttributedString *)attributedTitleForState:(UIControlState)state;

// 当前状态的title(只读)

NSString *currentTitle;

// 当前状态的title字体颜色(只读)

UIColor  *currentTitleColor;

// 当前状态的阴影(只读)

UIColor  *currentTitleShadowColor;

// 当前状态的图片(只读)

UIImage  *currentImage;

// 当前状态的背景图片(只读)

UIImage  *currentBackgroundImage;

// 当前状态的title的内容属性(只读 iOS 6.0)

NSAttributedString *currentAttributedTitle;

// UIButton的titleLabel(只读)

UILabel     *titleLabel;

// UIButton的contentImageView(只读)

UIImageView *imageView;

// 返回矩形的接收绘制其背景。

- (CGRect)backgroundRectForBounds:(CGRect)bounds;

// 返回矩形的接收提请其全部内容。

- (CGRect)contentRectForBounds:(CGRect)bounds;

// 返回title的绘制范围

- (CGRect)titleRectForContentRect:(CGRect)contentRect;

// 返回图片的绘制范围

- (CGRect)imageRectForContentRect:(CGRect)contentRect;





Comments