How to change textfield font size programmatically?

If you want to simply change your textfield's font size , and not change it's font style at the same time , code below may be work : `

UITextField *yourTextField = [[UITextField alloc]init];
CGFloat yourSelectedFontSize = 14.0 ;
UIFont *yourNewSameStyleFont = [yourTextField.font fontWithSize:yourSelectedFontSize];
yourTextField.font = yourNewSameStyleFont ;

One thing you have to note is that : when you change your textfield's font size , you should always pay attention to your textfield view's height , keep your textfiled's height taller than your font height !

You can have a try !


Swift 4 is this:

yourTextField.font =  UIFont.init(name: (Montserrat.bold.rawValue), size: 18.0)

Instead Monserrat use your font

Tags:

Xcode

Xcode4.3