I have a button that creates a text field, I also have a button to change the text field's font. I created 3 button with different titles: 17,20,36
. I want the functions of that button to change the font size of the text field, how can I do this?
You can't actually change the size of an existing Font object. The best way to achieve a similar effect is to use the deriveFont(size) method to create a new almost identical Font that is a different size.
To change the font-size of MUI you can provide a fontSize property. The default value is 14px .
Change the font size to increase TextField's height.In TextField there is a property style:TextStyle(); Inside the textstyle there is a property called font size. Then give the appropriate font size.
you can use NSAttributedString
to add properties to TextField
let textAttributes: [NSAttributedString.Key: Any] = [
NSAttributedString.Key.strokeColor: /* TODO: fill in appropriate UIColor */,
NSAttributedString.Key.foregroundColor: /* TODO: fill in appropriate UIColor */,
NSAttributedString.Key.font: UIFont(name: "HelveticaNeue-CondensedBlack", size: 40)!,
NSAttributedString.Key.strokeWidth: /* TODO: fill in appropriate Float */
]
yourTextField.defaultTextAttributes = textAttributes
Swift 4:
textField1.font = UIFont(name: "Avenir", size: 22)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With