文本属性未显示在丰富的UITextView(iOS 6)中

时间:2012-10-10 11:27:08

标签: iphone ios ios6 uitextview nsattributedstring

我正在尝试为iOS 6 UITextView中的某些初始文本设置字体颜色。在UI 6模拟器中运行时,视图会出现,但不会呈现属性。我错过了什么吗?

NSAttributedString *as = [[NSAttributedString alloc] initWithString:boilerText
    attributes:[NSDictionary dictionaryWithObjectsAndKeys:
      NSForegroundColorAttributeName, [UIColor redColor] ,
      NSUnderlineStyleAttributeName,
          [NSNumber numberWithInt:  NSUnderlineStyleSingle],nil]
      ];

_descriptionView.attributedText = as;

1 个答案:

答案 0 :(得分:8)

该方法表示dictionaryWithObjectsAndKeys。你已经完成了对象和键的反转。试试这个:

NSAttributedString *as = [[NSAttributedString alloc] initWithString:boilerText
     attributes:[NSDictionary dictionaryWithObjectsAndKeys:
     [UIColor redColor], NSForegroundColorAttributeName, 
     [NSNumber numberWithInt: NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
     nil]];