UITextView font to always be fixed size

徘徊边缘 提交于 2019-11-28 12:49:16

问题


I have a UICollectionView with cells sized to the same aspect ratio as a4 page. And with different screen sizes I would like for that text to be sized at fixed 12pt (that would be calculated to that UICollectionview cell), which would look bigger on the iPad and smaller on iPhone.

So having a fixed font size isn't an option...


回答1:


Coding

var fontSize : CGFloat = 12.0 // DEFAULT SIZE

In your ViewDidLoad

if UIDevice().userInterfaceIdiom == .phone {
    switch self.view.frame.size.height {
    case 480:
        fontSize = 12.0
    case 568:
        fontSize = 14.0
    case 667:
        fontSize = 16.0
    case 736:
        fontSize = 17.0
    case 812:
        fontSize = 18.0
    default:
        print("unknown")
    }
}
else if UIDevice().userInterfaceIdiom == .pad {

    fontSize = 20.0

}

Then apply this fontSize, wherever u need.

Storyboard

Select UITextView, in Attributes Inspector area, + (plus) symbol is near to Font. By default it will work for iPhone devices. For iPad, Change change size classes to Regular width and Regular Height wR hR . For, that U can increase font size.



来源:https://stackoverflow.com/questions/48630776/uitextview-font-to-always-be-fixed-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!