1 1> UIButton内部默认有个UIImageView、UILabel控件,可以分别用下面属性访问:
 2 @property(nonatomic,readonly,retain) UIImageView *imageView;
 3 @property(nonatomic,readonly,retain) UILabel     *titleLabel;
 4 
 5 2> UIButton之所以能显示文字,完全是因为它内部的titleLabel
 6 也就是说,UIButton的setTitle:forState:方法设置的字符串就是显示到了titleLabel上
 7 
 8 3> UIButton的setImage:forState:方法设置的图片显示到了内部的imageView上
 9 
10 4> 注意
11 * 设置按钮的文字或文字颜色,必须用下面的方法
12 - (void)setTitle:(NSString *)title forState:(UIControlState)state;
13 - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
14 #warnning 不能直接拿到titleLabel设置文字和文字颜色,比如下面的做法是错误的:
15 button.titleLabel.text = @"12323";
16 button.titleLabel.textColor = [UIColor redColor];
17 
18 * 设置按钮内部的小图片,必须用下面的方法
19 - (void)setImage:(UIImage *)image forState:(UIControlState)state;
20 #warnning 不能直接拿到imageView设置图片,比如下面的做法是错误的:
21 button.imageView.image = [UIImage imageNamed:@"abc.png"];

 

相关文章:

  • 2021-07-25
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-07-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-09-18
  • 2021-08-17
相关资源
相似解决方案