NSAttributedString 是一个特殊的类,可以用来操作富文本.继承自NSObject
NSAttributedString 里面包含一个类似NSString,同事还存储了有关文本格式的信息,比如字体.颜色等。从IOS6出现之后正式登上台面。
NSDictionary *attributes = @{NSForegroundColorAttributeName: [UIColor greenColor]};
NSAttributedString *aString = [[NSAttributedString alloc] initWithString:@"Green message!" attributes:attributes];
把字典换成
NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor greenColor],NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle]};
下面是一些常见的属性