Reputation: 141
How to adjust UITextfield font size when it is hold long character? I tried adjustsFontSizeToFitWidth. it is not working. any help will be appricated.thanks in advance
Upvotes: 5
Views: 6930
Reputation: 1253
Working Swift 4 Solution
Make sure you set adjustsFontSizeToFitWidth
to true
and then set your minimumFontSize
. This will scale the text inside the UITextField
to fit the width of your UITextField
with a minimum font size equal to or greater than what you set minimumFontSize
to. When the text is still too long to scale down to fit at the minimum font size it will truncate the rest.
textField.adjustsFontSizeToFitWidth = true
textField.minimumFontSize = 10
Upvotes: 4
Reputation: 651
With a UITextField, text must fit on one line and cannot wrap.
You have two options:
Shrink the font to fit on one line:
self.TextFieldExample.adjustsFontSizeToFitWidth = YES;
self.TextFieldExample.minimumFontSize = 10.0; //Optionally specify min size
Use UITextView to enable text wrapping:
Upvotes: 9
Reputation: 3464
You have to set the width first
textField.frame = CGRect(0, 0, your width, your height)
And
textField.minimumFontSize = 0.5
Upvotes: -1