ios关于uibutton内部结构

 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"];
原文地址:https://www.cnblogs.com/changxs/p/4040306.html