uibutton和iphone / ipad的uilabel不同的字体大小 [英] Different font sizes for uibutton and uilabel for iphone/ipad

查看:192
本文介绍了uibutton和iphone / ipad的uilabel不同的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个测验游戏,它开始作为一个iPhone应用程序,现在它已经完全工作,我想使它成为一个通用的应用程序,但我找不到一种方法来设置字体大小为一个值为所有iphones和ipad的另一个

我尝试使用界面生成器中的自动缩小菜单,但它只适用于标签,如果我通过代码uibutton代码不起作用,这是我写在里面的代码viewdidload

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

对于标签我使用的界面生成器,它的工作原理,但标签改变字体大小,每当它内部的文本改变



我怎么能把一个值的字体大小对于所有的iphones和所有ipad的值?我可以用接口生成器或通过代码吗?
也许我可以把一个值在界面生成器和一些条件在viewdidload改变大小,如果设备是一个ipad的



谢谢

解决方案

您可以随时检查设备类型。
$ b $ pre $ if $($)$ iPad的标签字体大小
}
else
{
// iPhone的标签字体大小
}



pre $ 枚举UIUserInterfaceIdiom:Int {
案例未指定
案例电话// iPhone和iPod touch风格UI
案例Pad // iPad风格UI
}


I am working on a quiz game,it started as an iphone app,now it is fully working and i want to make it an universal app,but i can't find a way to set the font size to one value for all iphones and another for the ipad

I tried with the auto shrink menu in the interface builder,but it works only for labels,and if i do the same via code for uibutton the code doesn't work,this is the code i wrote inside viewdidload

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

For the label i used interface builder and it works but the labels changes the font size every time the text inside it changes

How can i put a value for the font size for all iphones and a value for all ipads?Can i do it with interface builder or via code? Maybe can i put a value in interface builder and some condition in viewdidload to change the size if the device is an ipad

Thanks

解决方案

You can always check for device type.

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

We have a enum to define for device type check.

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

这篇关于uibutton和iphone / ipad的uilabel不同的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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