UITextView 字体总是固定大小 [英] UITextView font to always be fixed size

查看:33
本文介绍了UITextView 字体总是固定大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UICollectionView 单元格的大小与 a4 页面的纵横比相同.对于不同的屏幕尺寸,我希望该文本的大小固定为 12pt(将计算到 UICollectionview 单元格),这在 iPad 上看起来更大,在 iPhone 上看起来更小.

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...

推荐答案

编码

var fontSize : CGFloat = 12.0 // DEFAULT SIZE

在您的 ViewDidLoad

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

}

然后在您需要的任何地方应用此 fontSize.

Then apply this fontSize, wherever u need.

故事板

选择UITextView,在Attributes Inspector区域,+(加号)符号靠近Font.默认情况下,它适用于 iPhone 设备.对于 iPad,将更改大小类更改为常规宽度和常规高度 wR hR .因为,你可以增加字体大小.

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.

这篇关于UITextView 字体总是固定大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆