I have a UITextView with some texts. I want the big screen has bigger font size but the format is same. How can I do this?
I know it's a bit more advanced than the code-only solutions you've already found here, but I would encourage you to take some time and read about Adaptive Layouts: it's the future of UI development for different screens on iOS.
For instance, you can target different screen sizes and orientations using size classes. You can get an overview here: width & height traits .
Here are a few pointers if you need to begin from zero:
You can detect the screen size of the device using UIScreen.mainScreen().bounds.height
and depending on the screen size you are you set a different font size.
See example below:
let screenHeight = UIScreen.mainScreen().bounds.height
switch screenHeight {
case 480: // 3.5 inch
UIFont(name: "Helvetica", size: 16)
case 568: // 4 inch
UIFont(name: "Helvetica", size: 17)
default: // rest of screen sizes
UIFont(name: "Helvetica", size: 20)
}
Here you can check out the screen sizes here
Here are all screen sizes :)
let screenWidth = self.view.frame.size.width
switch screenWidth {
case 320: // iPhone 4 and iPhone 5
label.font = UIFont(name: "Avenir-Book", size: 16)
case 375: // iPhone 6
label.font = UIFont(name: "Avenir-Book", size: 18)
case 414: // iPhone 6 Plus
label.font = UIFont(name: "Avenir-Book", size: 20)
case 768: // iPad
label.font = UIFont(name: "Avenir-Book", size: 25)
default: // iPad Pro
label.font = UIFont(name: "Avenir-Book", size: 30)
}
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.