Change the color of the message UIAlertController in Swift
You can use attributedStrings
to create the color, font, size, and style that you want, and then set the string as the title.
EDIT: Updated with example
let attributedString = NSAttributedString(string: "Invalid Name", attributes: [
NSParagraphStyleAttributeName: paragraphStyle,
NSFontAttributeName : UIFont.systemFontOfSize(15),
NSForegroundColorAttributeName : UIColor.redColor()
])
let alert = UIAlertController(title: "Title", message: "", preferredStyle: .Alert)
alert.setValue(attributedString, forKey: "attributedMessage")
let cancelAction = UIAlertAction(title: "Cancel",
style: .Default) { (action: UIAlertAction!) -> Void in
}
presentViewController(alert,
animated: true,
completion: nil)
How to change tint color of UIAlertController?
You could just change the tintColor
of the underlying view, however, due to a known bug introduced in iOS 9 (https://openradar.appspot.com/22209332), the tintColor is overridden by the application window's tintColor
.
You can either:
Change the app
tintColor
in the AppDelegate.func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
self.window.tintColor = UIColor.redColor()
return true
}Reapply the color in the completion block.
self.presentViewController(alert, animated: true, completion: {() -> Void in
alert.view.tintColor = UIColor.redColor()
})
Change title color in UIAlertController
only red Color is possible when you set UIAlertActionStyle.Destructive
Check this link
UIAlertController custom font, size, color
How to change font color on UIAlertController on particular action sheet?
Use .destructive
instead of .default
for the action style.
Change UIAlertController text color
Yes you can do that using this
alert.view.tintColor = UIColor.redColor() // your custom color
How to change UIAlertController button text colour in iOS9?
I've run into something similar in the past and the issue seems to stem from the fact that the alert controller's view isn't ready to accept tintColor
changes before it's presented. Alternatively, try setting the tint color AFTER you present your alert controller:
[self presentViewController:strongController animated:YES completion:nil];
strongController.view.tintColor = [UIColor black];
Related Topics
Why Is There a Memory Leak at String Creation in Swift
What Is Import Func, Struct, Class, and @_Exported in Swift
How to Create a Hud on Top of My Scenekit.Scene
What's the Best Approach to Prefill Core Data Store When Using Nspersistentcloudkitcontainer
Swiftui: How Do Style Text View with Different Font and Colour on String Subranges
Swift - How to Save Audio from Avaudioengine, or from Audioplayernode? If Yes, How
Performseguewithidentifier in Swift
How to Make a Swift Framework Submodule Really Private
How to Rounded the Corners When I Draw Rectangle Using Uibezierpath Points
Stopping an Running Skaction - Sprite Kit
Swift Uifont Ibinspectable - Is It Possible
How Safe Are Swift Collections When Used with Invalidated Iterators/Indices