Although new to iOS programming, I encountered the same problem very quickly. In iOS, my experience is that
- Lewis42's problem occurs consistently
- josef's suggestion of extracting and reapplying the attributes does
not work: a null attributes dictionary is returned.
Having looked around s/o, I came across This Post and followed that recommendation, I ended up using this:
- (NSMutableAttributedString *)SetLabelAttributes:(NSString *)input col:(UIColor *)col size:(Size)size {
NSMutableAttributedString *labelAttributes = [[NSMutableAttributedString alloc] initWithString:input];
UIFont *font=[UIFont fontWithName:@"Helvetica Neue" size:size];
NSMutableParagraphStyle* style = [NSMutableParagraphStyle new];
style.alignment = NSTextAlignmentCenter;
[labelAttributes addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, labelAttributes.length)];
[labelAttributes addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, labelAttributes.length)];
[labelAttributes addAttribute:NSForegroundColorAttributeName value:col range:NSMakeRange(0, labelAttributes.length)];
return labelAttributes;