Setting NSForegroundColorAttributeName on an attributed string shifts the text down on iOS 6

Alexis picture Alexis · Oct 24, 2013 · Viewed 8.5k times · Source

I'm using attributed strings in my iOS app to give the text some style:

NSDictionary *titleAttributes = @{NSFontAttributeName:              [UIFont fontWithName:@"Raleway" size:12],
                                  NSForegroundColorAttributeName:   [UIColor lightGreyTextColor]};

NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:title attributes:titleAttributes];

The problem is that on iOS 6, the text is not vertically centered in the UILabel anymore. On iOS 7 it's fine.

I found that when I remove the NSForegroundColorAttributeName attribute then it's correctly centered but the text is black

Does anyone know a way to fix that? Is it a bug in iOS or am I missing something?

Answer

lootsch picture lootsch · Mar 18, 2014

Try to use UITextAttributeTextColor instead of NSForegroundColorAttributeName.

Seems to be the same issue, as in this question.