简体   繁体   中英

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. 在此处输入图片说明

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.

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.

Try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM