UIButton - 常用方法总结

[color=red]注 : 文章不断更新,转载文章请加上作者[/color]


// 设置按钮的文字  title : 需要设置的文字   state : 该文字显示的状态
- (void)setTitle:(NSString *)title forState:(UIControlState)state;

// 设置按钮的文字颜色 color : 设置颜色 state : 该文字颜色显示的状态
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;

// 设置按钮内部的小图片 state : 该图片显示的状态
- (void)setImage:(UIImage *)image forState:(UIControlState)state;

// 获取按钮上传入的状态的文本 state : 需要获取文本的状态
- (NSString *)titleForState:(UIControlState)state;

// 设置按钮的背景图片 image: 图片 state 该图片显示的状态
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state

// 获取按钮内部的小图片
- (UIImage *)imageForState:(UIControlState)state;

//获取按钮内部的背景图片
- (UIImage *)backgroundImageForState:(UIControlState)state;

//获取按钮的文字颜色
- (UIColor *)titleColorForState:(UIControlState)state;


// 按钮中,包括了一个 UILabel 和一个 UIImageView 的子控件
// 所以设置按钮的文字字体,就获取UILabel,去设置Font属性
// @property(nonatomic,readonly,retain) UILabel *titleLabel
// @property(nonatomic,readonly,retain) UIImageView *imageView

UIButton *btnTest = [[UIButton alloc] init];
btnTest.titleLabel.font = [UIFont systemFontOfSize:13];



[color=blue][size=medium]UIButton有很多状态,它提供了一些便捷属性, 可以直接获取当前状态下得文字, 文字颜色 , 图片等.[/size][/color]


@property (nonatomic, readonly, retain) NSString *currenTitle; // 获取文字
@property (nonatomic, readonly, retain) UIColor *currenTitleColor; // 获取文字颜色
@property (nonatomic, readonly, retain) UIImage *currenImage// 获取按钮内部小图片
@property (nonatomic, readonly, retain) UIImage *currenBackGroundImagel; // 获取按钮背景图片
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值