UIButton中设置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;
|
|