您的位置:首页 > 其它

AttributedString

2016-06-22 11:00 169 查看

AttributedString的初始化

通常初始化AttributedString的方式有两种:


NSString *str = @"Hello, the Word!";
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString: str];

UILabel *textLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 64, 300, 50)];
textLabel1.numberOfLines = 0;
textLabel1.textAlignment = NSTextAlignmentLeft;
[self.view addSubview:textLabel1];

NSString *str = @"textLabel1: Hello, the Word!";
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:str];
[attribute addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"zapfino" size:15.0] range:NSMakeRange(0, str.length)];
[attribute addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(12, 4)];
[attribute addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(16, 5)];
textLabel1.attributedText = attribute;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: