John
John

Reputation: 258

Setting UITextView font size based for different devices

Sorry for my poor english.

I have UITextview, which is configured with Auto layout. So it's height will change depends on devices. So it should take the font size, in such way that it show only one line available space. like SMS box or Chat box.enter image description here

See the pictures for iPhone4 it shows only one line and for iPhone 6s and 5s it shows two lines. But for me it should increase font size and show only one line for any size.

Upvotes: 1

Views: 449

Answers (2)

markhorrocks
markhorrocks

Reputation: 1418

Try this

if UIDevice.current.userInterfaceIdiom == .pad {
    textView.font = UIFont.systemFont(ofSize: 14.0)
} else {
    textView.font = UIFont.systemFont(ofSize: 12.0)
}

Upvotes: 1

Gourav Joshi
Gourav Joshi

Reputation: 2419

Using this:

static let SCREEN_WIDTH = UIScreen.main.bounds.size.width

you can check the condition:

if(SCREEN_WIDTH == 320) {
   textView.font = UIFont.systemFont(ofSize: 12.0)
} else if(SCREEN_WIDTH == 375) {
   textView.font = UIFont.systemFont(ofSize: 13.0)
} else if(SCREEN_WIDTH == 414) {
   textView.font = UIFont.systemFont(ofSize: 14.0)
} 

By this the font size will be adjust according to device.

Upvotes: 1

Related Questions