UIAlertController custom font, size, color UIAlertController custom font, size, color ios ios

UIAlertController custom font, size, color


Not sure if this is against private APIs/properties but using KVC works for me on ios8

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Dont care what goes here, since we're about to change below" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"Presenting the great... Hulk Hogan!"];[hogan addAttribute:NSFontAttributeName              value:[UIFont systemFontOfSize:50.0]              range:NSMakeRange(24, 11)];[alertVC setValue:hogan forKey:@"attributedTitle"];UIAlertAction *button = [UIAlertAction actionWithTitle:@"Label text"                                         style:UIAlertActionStyleDefault                                        handler:^(UIAlertAction *action){                                                    //add code to make something happen once tapped}];UIImage *accessoryImage = [UIImage imageNamed:@"someImage"];[button setValue:accessoryImage forKey:@"image"];

For the record, it is possible to change alert action's font as well, using those private APIs. Again, it may get you app rejected, I have not yet tried to submit such code.

let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)let action = UIAlertAction(title: "Some title", style: .Default, handler: nil)let attributedText = NSMutableAttributedString(string: "Some title")let range = NSRange(location: 0, length: attributedText.length)attributedText.addAttribute(NSKernAttributeName, value: 1.5, range: range)attributedText.addAttribute(NSFontAttributeName, value: UIFont(name: "ProximaNova-Semibold", size: 20.0)!, range: range)alert.addAction(action)presentViewController(alert, animated: true, completion: nil)// this has to be set after presenting the alert, otherwise the internal property __representer is nilguard let label = action.valueForKey("__representer")?.valueForKey("label") as? UILabel else { return }label.attributedText = attributedText

For Swift 4.2 in XCode 10 and up the last 2 lines are now:

guard let label = (action!.value(forKey: "__representer")as? NSObject)?.value(forKey: "label") as? UILabel else { return }        label.attributedText = attributedText


You can change the button color by applying a tint color to an UIAlertController.

On iOS 9, if the window tint color was set to a custom color, you have to apply the tint color right after presenting the alert. Otherwise the tint color will be reset to your custom window tint color.

// In your AppDelegate for example:window?.tintColor = UIColor.redColor()// Elsewhere in the App:let alertVC = UIAlertController(title: "Title", message: "message", preferredStyle: .Alert)alertVC.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))alertVC.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))// Works on iOS 8, but not on iOS 9// On iOS 9 the button color will be redalertVC.view.tintColor = UIColor.greenColor()self.presentViewController(alert, animated: true, completion: nil)// Necessary to apply tint on iOS 9alertVC.view.tintColor = UIColor.greenColor()


You can change color of button text using this code:

alertC.view.tintColor = your color;

Maybe this will help you.