1
votes

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.

2
hi john, do you want to show font size depend on device size? - Piyush Sinroja
github.com/IosPower/PerfectUISwift3 : Very Very Useful for UIRelated (Font Size, Constraints Size Pixel To Pixel) - Piyush Sinroja

2 Answers

1
votes

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.

1
votes

Try this

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