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 UIAlertAction font or show UIAlertActionStyle.cancel style ActionButton on second position?
Swift 4.2/Swift 5
You need to set preferred action method,
//Create alertController
let alert = UIAlertController(title: "title", message: "message", preferredStyle: .alert)
//Create and add the Confirm action
let confirmAction = UIAlertAction(title: "Confirm", style: .default, handler: { (action) -> Void in
//Do Something here...
})
alert.addAction(confirmAction)
//Create and add the Cancel action
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) -> Void in
//Do Something here...
})
alert.addAction(cancelAction)
// Set Preferred Action method
alert.preferredAction = confirmAction
self.present(alert, animated: true, completion: nil)
The output will be,
Related Topics
iOS 11 Uibarbuttonitem Images Not Sizing
Mfmailcomposeviewcontroller Crashes Because of Global Appearance Properties on iOS6
How to Specify a Platform Target When Running Swift Test from the Cli
Play Audio from Internet Using Avaudioplayer
Tap Gesture on Animating Uiview Not Working
Is There Any Facebook Plugin for Phonegap 2.7.0
Spritekit: Why Does It Wait One Round for the Score to Update? (Swift)
Different Cornerradius for Each Corner Swift 3 - iOS
-[Not a Type Retain]: Message Sent to Deallocated Instance
Adding Quartzcore to Xcode 4 for iOS
How to Get File Name in Uiimagepickercontroller with Asset Library
How to Edit Uialertaction Title Font Size and Style
iOS 7 - Restrict Landscape Orientation Only in One View Controller
Is This Code Drawing at the Point or Pixel Level? How to Draw Retina Pixels
How to Read Plist Without Using Nsdictionary in Swift
How to Display Remote Document Using Qlpreviewcontroller in Swift