swiftuitextfielduialertcontroller

How to change UITextField Font size within an Alert


I'm trying to make my font size larger in the textField that is currently placed within an alert:

func showAlert() {
    let ac = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
    
    // Add text field
    ac.addTextField(configurationHandler: { textField in
        
        
        let heightConstraint = NSLayoutConstraint(item: textField, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 100)
        textField.addConstraint(heightConstraint)
   
        textField.minimumFontSize = 100
        
    })

Solution

  • Change textField.minimumFontSize = 100 line to textField.font = UIFont(name: "*whateverFontNameYouAreUsing*", size: 30). Let me know if this worked. Thanks.

    check this code and font size in simulator here