AttributedText 快速設(shè)置UIButton 和 UILabel 的文字: 字體、顏色、大小

#import"ViewController.h"

@interfaceViewController()

@property(weak,nonatomic)IBOutletUIButton*loginbutton;

@property(weak,nonatomic)IBOutletUILabel*lable;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

//**用富文本快速設(shè)置Label的文字:字體,大小,顏色

NSMutableParagraphStyle*ps = [[NSMutableParagraphStylealloc]init];

//可以通過ps設(shè)置行距,間距,對齊方式,拆行方式

[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;

//**用富文本快速設(shè)置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.

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容