Change color to attributedTitle in UIRefreshControl

Fry picture Fry · Oct 9, 2012 · Viewed 7.9k times · Source

I'm looking for a way to change color in UIRefreshControl. The text is shown in an NSAttributedString, so I try to use CoreText.framework:

 NSString *s = @"Hello";
 NSMutableAttributedString *a = [[NSMutableAttributedString alloc] initWithString:s];
 [a addAttribute:(id)kCTForegroundColorAttributeName value:(id)[UIColor redColor].CGColor range:NSRangeFromString(s)];
 refreshControl.attributedTitle = a;

The text is shown correctly, but the color is always the default gray. Any ideas ?

Answer

Dave DeLong picture Dave DeLong · Oct 9, 2012

You should be using NSForegroundColorAttributeName, not kCTForegroundColorAttributeName.


Also, the range being passed should be NSMakeRange(0, [s length]);.