Search code examples
ios10uialertcontrollernsmutableattributedstring

NSMutableAttributeString not working in iOS 10.0 in UIAlertController


Hello am using NSMutableAttributedString to show different fonts but with same size in UIAlertController, the problem here is it showing two different fonts which is correct but it also showing two different sizes.Here is my code

 UIFont *regularFont = [UIFont fontWithName:@"HelveticaNeue" size:11.0];
UIFont *boldFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:11.0];

UIAlertController *alertObj = [UIAlertController alertControllerWithTitle:nil message:messageStr preferredStyle:UIAlertControllerStyleAlert];

NSMutableAttributedString *attMessage = [[NSMutableAttributedString alloc] initWithString:messageStr];
[attMessage addAttribute:NSFontAttributeName value:regularFont range:NSRangeFromString(messageStr)];
[attMessage addAttribute:NSFontAttributeName value:boldFont range:NSMakeRange(25, 6)];
[attMessage addAttribute:NSFontAttributeName value:boldFont range:NSMakeRange(35, 15)];

[alertObj setValue:attMessage forKey:@"attributedMessage"];

Result can be match.Any help would be appreciated

enter image description here


Solution

  • The attributedMessage property is not public, using it is a good way to get your app rejected at the review. If you really need to style the dialogue and distribute the app on the App Store, I think you should build your own component to display the pop-up.