美文网首页
AttributedText 快速设置UIButton 和 UI

AttributedText 快速设置UIButton 和 UI

作者: 酒红色T恤 | 来源:发表于2016-05-27 00:26 被阅读2005次

#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.

}

相关文章

网友评论

      本文标题:AttributedText 快速设置UIButton 和 UI

      本文链接:https://www.haomeiwen.com/subject/rkixdttx.html