Change UIAlertController's title fontsize
You can make title and message of UIAlertController
attributed by using this code. You can customize as per your need. You can see the result in the image. I am not sure you can put it on Appstore.
func showAlert() {
let alert = UIAlertController(title: "", message: "", preferredStyle: .actionSheet)
let titleAttributes = [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue-Bold", size: 25)!, NSAttributedStringKey.foregroundColor: UIColor.black]
let titleString = NSAttributedString(string: "Name Last name", attributes: titleAttributes)
let messageAttributes = [NSAttributedStringKey.font: UIFont(name: "Helvetica", size: 17)!, NSAttributedStringKey.foregroundColor: UIColor.red]
let messageString = NSAttributedString(string: "Company name", attributes: messageAttributes)
alert.setValue(titleString, forKey: "attributedTitle")
alert.setValue(messageString, forKey: "attributedMessage")
let labelAction = UIAlertAction(title: "Label", style: .default, handler: nil)
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: nil)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alert.addAction(labelAction)
alert.addAction(deleteAction)
alert.addAction(cancelAction)
self.navigationController?.present(alert, animated: true, completion: nil)
}
How to change font color on UIAlertController on particular action sheet?
Use .destructive
instead of .default
for the action style.
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)
Related Topics
React-Native, How to Get File-Asset Image Absolute Path
React Native App Crashes on Launch Screen on Device
How to Export Uiimage Array as a Movie
Instantiate and Present a Viewcontroller in Swift
Expand/Collapse Section in Uitableview in Ios
Programmatically Set the Initial View Controller Using Storyboards
How to Change Image Tintcolor in iOS and Watchkit
Get Location Updates For iOS App Even When Suspended
How to Get the Root Directory of My iOS App
Remove Alpha Channel in an Image
How to Associate File Types With an Iphone Application
How to Input Currency Format on a Text Field (From Right to Left) Using Swift
Ios 9 Not Opening Instagram App With Url Scheme