Steven Lowenthal
Steven Lowenthal

Reputation: 656

Text attributes not showing up in rich UITextView (iOS 6)

I'm trying the set the font color for some initial text in a iOS 6 UITextView. When running in the UI 6 simulator, the view comes up, but the attributes aren't rendered. Am I missing something?

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

_descriptionView.attributedText = as;

Upvotes: 2

Views: 1349

Answers (1)

sosborn
sosborn

Reputation: 14694

The method says dictionaryWithObjectsAndKeys. You've gotten your objects and keys reversed. Try this:

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

Upvotes: 8

Related Questions