UIButton是UIControl子类,这个类提供了方法来设置标题,图像,按钮等外观属性。通过使用set方法,你可以指定一个不同的外观为每个按钮状态。
// typedef enum {
// UIButtonTypeCustom = 0, 自定义风格
// UIButtonTypeRoundedRect, 圆角矩形
// UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用
// UIButtonTypeInfoLight, 亮色感叹号
// UIButtonTypeInfoDark, 暗色感叹号
// UIButtonTypeContactAdd, 十字加号按钮
// } UIButtonType;
+ (id)buttonWithType:(UIButtonType)buttonType;
// contentEdgeInsets : 切掉按钮内部的内容
// imageEdgeInsets : 切掉按钮内部UIImageView的内容
// titleEdgeInsets : 切掉按钮内部UILabel的内容
shareButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
UIEdgeInsets contentEdgeInsets; // default is UIEdgeInsetsZero
UIEdgeInsets titleEdgeInsets; // default is UIEdgeInsetsZero
BOOL reversesTitleShadowWhenHighlighted; // default is NO. if YES, shadow reverses to shift between engrave and emboss appearance
UIEdgeInsets imageEdgeInsets; // default is UIEdgeInsetsZero
BOOL adjustsImageWhenHighlighted; // default is YES. 默认情况下,当按钮高亮的情况下,图像的颜色会被画深一点,如果这下面的这个属性设置为no,那么可以去掉这个功能
BOOL adjustsImageWhenDisabled; // default is YES. 默认情况下,当按钮禁用的时候,图像会被画得深一点,设置NO可以取消设置
BOOL showsTouchWhenHighlighted; // default is NO. 设置为yes的状态下,按钮按下会发光
UIColor *tintColor; // The tintColor is inherited through the superview hierarchy. See UIView for more information.
UIButtonType buttonType;
- (void)setTitle:(NSString *)title forState:(UIControlState)state //设置标题
- (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 //设置背景图片
- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state // 设置标题 ,标题被设定为单行,,
@property(nonatomic,readonly,retain) UILabel *titleLabel // 直接设置titleLabel属性不显示,原因是titleLabel的frame默认是0,hidden=yes;
@property(nonatomic,readonly,retain) UIImageView *imageView