iphone/ipad 的 uibutton 和 uilabel 的不同字体大小

Different font sizes for uibutton and uilabel for iphone/ipad

我正在开发一款问答游戏,它最初是一个 iphone 应用程序,现在它已经完全可用了,我想让它成为一个通用应用程序,但我找不到设置所有 iphone 的字体大小为一个值,ipad

的字体大小为另一个值

我尝试在界面生成器中使用自动收缩菜单,但它仅适用于标签,如果我通过 uibutton 代码执行相同操作,代码将不起作用,这是我在 viewdidload[ 中编写的代码=12=]

ans2b.titleLabel?.numberOfLines = 1
ans2b.titleLabel?.adjustsFontSizeToFitWidth = true
ans2b.titleLabel?.minimumScaleFactor = 2

对于标签,我使用了 interface builder 并且它可以工作,但是标签会在每次其中的文本发生变化时更改字体大小

我如何为所有 iphone 设置一个字体大小值和为所有 ipad 设置一个值?我可以使用界面生成器或通过代码来完成吗? 如果设备是 ipad

,也许我可以在 interface builder 中放置一个值并在 viewdidload 中放置一些条件来更改大小

谢谢

您可以随时检查设备类型。

if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad)
    {
        //label font size for iPad
    }
    else
    {
        //label font size for iPhones
    }

我们有一个枚举来定义设备类型检查。

    enum UIUserInterfaceIdiom : Int {
    case Unspecified
    case Phone // iPhone and iPod touch style UI
    case Pad // iPad style UI
}