Reputation: 1097
I have a UIButton that I've given an attributed title in Interface Builder: it has a specific font, and one part of the string is a different color.
When I load my app, the color is maintained, but the app reverts the font back to system default...
Anyone experience this or know a way to fix? Was trying to avoid having to set the attributed titles in code.
If it matters, the font I'm using is Open Sans, and it displays correctly on other labels where I've specified the font in code.
Upvotes: 13
Views: 2715
Reputation: 5201
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setAlignment:NSTextAlignmentCenter];
[style setLineBreakMode:NSLineBreakByWordWrapping];
NSDictionary *dict1 = @{NSFontAttributeName:[UIFont fontWithName:@"Varela Round" size:15.0f],
NSForegroundColorAttributeName:[UIColor whiteColor],
NSParagraphStyleAttributeName:style};
NSDictionary *dict2 = @{NSFontAttributeName:[UIFont fontWithName:@"Varela Round" size:10.0f],
NSForegroundColorAttributeName:[UIColor whiteColor],
NSParagraphStyleAttributeName:style};
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] init];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Expensed\n" attributes:dict1]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Tap to edit" attributes:dict2]];
[cell.expenseTripButton setAttributedTitle:attString forState:UIControlStateNormal];
[[cell.expenseTripButton titleLabel] setNumberOfLines:0];
[[cell.expenseTripButton titleLabel] setLineBreakMode:NSLineBreakByWordWrapping];
Upvotes: 0
Reputation: 118
I had the same issue a week ago. I was using Open Sans, too. But every time I tried to build I got a compilation error that pointed nowhere.
Anyway.. I just added a label to the button and configured it the way I wanted.
Upvotes: 0