gpt4 book ai didi

iOS 不同设备的单一大小类中的不同字体大小

转载 作者:IT王子 更新时间:2023-10-29 08:13:45 26 4
gpt4 key购买 nike

在 iOS 8 中,我们可以为每个尺码类别设计不同的 UI 布局。我面临的问题是,我已经设计了紧凑宽度和常规高度的布局(所有 iPhone 的纵向尺寸等级),但我想为 3.5 和 4 英寸设备(iPhone 4 和 5)保持更小的标签字体大小),然后 4.7 英寸 (iPhone 6) 设备相对更大,5.5 英寸 (iPhone 6 Plus) 设备更大。我搜索过但无法找到为相同大小级别的不同设备设置不同字体大小的解决方案。

最佳答案

编辑:我不再推荐这个了。当新设备问世时,这种方法无法很好地扩展。结合使用动态字体大小和特定于大小类别的字体。


假设一款新的 iPhone 机型问世,如果您使用自动布局和尺寸类,则无需手动修复所有约束即可使您的应用与这款新设备兼容。但是,您仍然可以使用以下代码设置 UILabel 的字体大小:

if UIScreen.mainScreen().bounds.size.height == 480 {
// iPhone 4
label.font = label.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.height == 568 {
// IPhone 5
label.font = label.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 375 {
// iPhone 6
label.font = label.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 414 {
// iPhone 6+
label.font = label.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 768 {
// iPad
label.font = label.font.fontWithSize(20)
}

关于iOS 不同设备的单一大小类中的不同字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28076020/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com