iOS 中UIButton的 setTitle 和 titlel

2017-10-09  本文已影响106人  小小鱼类

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的值,但是运行出来确没显示文字。

setTitle:(NSString *)title forState:(UIControlState)state 设置 Title;
[button setAttributedTitle:[[NSAttributedString alloc]initWithString:@"3333333"] forState:UIControlStateNormal];

<UIButtonLabel: 0x8a75810b; frame = (0 0; 0 0); text = '11111111'; clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7572980>>

如果想设置UIButton:


UIButton *uibtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]; 

 或者
  
 UIButton *uibtn = [UIButton buttonWithType:UIButtonTypeCustom];

[uibtn setFrame:CGRectMake(0, 0, 100, 30)];

文章参考:
http://www.cnblogs.com/Yukang1989/p/3716753.html

小小总结,不成敬意

上一篇下一篇

猜你喜欢

热点阅读