UIButton中
来源:互联网 发布:买口红热 知乎 编辑:程序博客网 时间:2024/06/09 16:48
IButton中设置Titl方法包括以下几种:
- (void)setTitle:(NSString *)title forState:(UIControlState)state; - (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state @property(nonatomic,readonly,retain) NSString *currentTitle; @property(nonatomic,readonly,retain) UILabel *titleLabel;
在定义UIButton的时候,经常会使用titleLabel.text设置UIButton的值,但是Run出来确啥都没显示,不起作用啊!!!,这是怎么会事?难道是API的bug??
1.其实不是,正常使用UIButton的时候设置Title是要对应Button的ControlState,因为UIButton继承于UIControl,在设置值得时候需要对象状态,所以一般都会用
setTitle:(NSString *)title forState:(UIControlState)state 设置 Title;
2.setAttributedTitle是iOS6之后的方法,使用起来很简单,没特色说明。实例如下:
[uibutton setAttributedTitle:[[NSAttributedString alloc]initWithString:@"3333333"] forState:UIControlStateNormal];
3.对应的currentTitle 也就是/normal/highlighted/selected/disabled状态下的title值,属性为readOnly;
4.至于titleLabel是设置的时候为啥不显示,比较神奇。查了官方文档以后才发现,真正的原因再于:(以下是我使用UIButton打印titleLabel对象的结果)
po uibutton.titleLabel<UIButtonLabel: 0x7575800; frame = (0 0; 0 0); text = '11111111'; clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7572980>>
看到这里你明白了吗?
默认UIButton的titleLable是没设置frame的,而且hidden=YES;只要你设置这2个值就可以正常显示,
无论你采用何种方式生产UIButton:
UIButton *uibtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 100, 100, 30)]; UIButton *uibtn = [UIButton buttonWithType:UIButtonTypeCustom];[uibtn setFrame:CGRectMake(0, 100, 100, 30)];
0 0
- UIButton中
- iOS中UIButton详解
- iOS在UIButton中换行
- UIButton使用过程中注意
- iOS中UIButton的block
- iOS中 UIButton和UIImageView
- iOS中UIButton的使用
- UIButton中UIEdgeInsetsMake的用法
- swift中UIbutton的布局
- UIButton中UIImage的使用
- swift中UIButton的使用
- swift中UIButton的使用
- ios中UIButton的使用
- UIButton
- UIButton
- UIButton
- uibutton
- UIButton
- Java 的Hashtable和HashMap的区别
- 栈的出展顺序
- 关于指令、数据、程序和进程的一些思考
- 第12周项目2-操作用邻接表存储的图
- 实现图—构件图、部署图
- UIButton中
- 自动内存管理(ARC)
- 使用boost::property_tree解析xml与json (三):parse_json设计
- std::vector::iterator重载了下面哪些运算符
- 深入理解Linux修改hostname
- hdu 1195 Open the Lock(BFS && DBFS)
- 复杂数据类型
- java的io操作
- iOS UI 03 事件和手势