在丰富的UITextView(iOS 6)中未显示文本属性
问题描述:
我试图设置iOS 6 UITextView中某些初始文本的字体颜色。在UI 6模拟器中运行时,视图出现,但不显示属性。我错过了什么吗?在丰富的UITextView(iOS 6)中未显示文本属性
NSAttributedString *as = [[NSAttributedString alloc] initWithString:boilerText
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
NSForegroundColorAttributeName, [UIColor redColor] ,
NSUnderlineStyleAttributeName,
[NSNumber numberWithInt: NSUnderlineStyleSingle],nil]
];
_descriptionView.attributedText = as;
答
该方法说dictionaryWithObjectsAndKeys。你已经把你的物体和钥匙颠倒了。试试这个:
NSAttributedString *as = [[NSAttributedString alloc] initWithString:boilerText
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], NSForegroundColorAttributeName,
[NSNumber numberWithInt: NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
nil]];