Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change textfield font size programmatically?

Tags:

xcode

ios

swift

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?

like image 535
chineseGirl Avatar asked Nov 05 '12 03:11

chineseGirl


People also ask

How do you change text size in Java?

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.

How do you change the font size in TextField MUI?

To change the font-size of MUI you can provide a fontSize property. The default value is 14px .

How do I increase the font size in TextField flutter?

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.


2 Answers

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 
like image 132
Mohamed AbdelraZek Avatar answered Sep 17 '22 17:09

Mohamed AbdelraZek


Swift 4:

textField1.font = UIFont(name: "Avenir", size: 22)
like image 40
Amit Baderia Avatar answered Sep 20 '22 17:09

Amit Baderia