Home > Net >  How to change UITextField Font size within an Alert
How to change UITextField Font size within an Alert

Time:04-23

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: "Current Page Number", message: "What page number are you on?", preferredStyle: .alert)
    
    // Add text field
    ac.addTextField(configurationHandler: { textField in
        textField.placeholder = "\(self.currentReadsArray[0].pageCount)"
        
        let heightConstraint = NSLayoutConstraint(item: textField, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 100)
            textField.addConstraint(heightConstraint)
        textField.textAlignment = .center
        textField.keyboardType = .numberPad
        textField.minimumFontSize = 100
        
    })
    ac.addAction(UIAlertAction(title: "Submit", style: .default, handler: { _ in
        print("submit tapped")
      }))
    ac.addAction(UIAlertAction(title: "Skip", style: .cancel, handler: nil))
    present(ac, animated: true)
  }

CodePudding user response:

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

  • Related