AttributedString

来源:互联网 发布:mac flash player 21 编辑:程序博客网 时间:2024/06/11 01:06

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