如何在警报中更改 UITextField 字体大小
How to change UITextField Font size 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)
}
将 textField.minimumFontSize = 100
行更改为 textField.font = UIFont(name: "*whateverFontNameYouAreUsing*", size: 30)
。让我知道这是否有效。谢谢
check this code and font size in simulator here
我试图在当前放置在警报中的文本字段中增大我的字体大小:
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)
}
将 textField.minimumFontSize = 100
行更改为 textField.font = UIFont(name: "*whateverFontNameYouAreUsing*", size: 30)
。让我知道这是否有效。谢谢
check this code and font size in simulator here