AttributedText 快速设置UIButton 和 UI

2016-05-27  本文已影响2005人  酒红色T恤

#import"ViewController.h"

@interfaceViewController()

@property(weak,nonatomic)IBOutletUIButton*loginbutton;

@property(weak,nonatomic)IBOutletUILabel*lable;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

//**用富文本快速设置Label的文字:字体,大小,颜色

NSMutableParagraphStyle*ps = [[NSMutableParagraphStylealloc]init];

//可以通过ps设置行距,间距,对齐方式,拆行方式

[pssetAlignment:NSTextAlignmentCenter];// 居中对齐

NSDictionary*attribs=@{

NSFontAttributeName: [UIFontfontWithName:@"Verdana"size:50],

NSForegroundColorAttributeName:[UIColorredColor],NSParagraphStyleAttributeName:ps};

NSMutableAttributedString*attributedText =[[NSMutableAttributedStringalloc]initWithString:self.lable.textattributes:attribs];

self.lable.attributedText= attributedText;

//**用富文本快速设置UIbutton Title的文字:字体,大小,颜色

NSMutableAttributedString*attributedTextForButton =[[NSMutableAttributedStringalloc]initWithString:self.loginbutton.titleLabel.textattributes:attribs];

[self.loginbuttonsetAttributedTitle:attributedTextForButtonforState:UIControlStateNormal];

// Do any additional setup after loading the view, typically from a nib.

}

上一篇 下一篇

猜你喜欢

热点阅读