问题描述
我正在做一个测验游戏,它开始作为一个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不同的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!