首页 > 移动平台 > 详细

ios关于uibutton内部结构

时间:2014-10-21 15:18:41      阅读:341      评论:0      收藏:0      [点我收藏+]
 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"];

 

ios关于uibutton内部结构

原文:http://www.cnblogs.com/changxs/p/4040306.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!