2

我正在尝试为 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;
4

1 回答 1

8

该方法说dictionaryWithObjectsAndKeys。你已经把你的对象和钥匙颠倒了。尝试这个:

NSAttributedString *as = [[NSAttributedString alloc] initWithString:boilerText
     attributes:[NSDictionary dictionaryWithObjectsAndKeys:
     [UIColor redColor], NSForegroundColorAttributeName, 
     [NSNumber numberWithInt: NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
     nil]];
于 2012-10-10T11:34:06.223 回答