Swift 如何为iphone4s、5设置相同的字体和按钮大小,为iPhone6和6+设置不同的字体和按钮大小;设备?
我正在开发一个iOS应用程序,我观察了iPhone 5、6、6+的用户界面。每个设备的所有字体都不同,但我的要求是,iPhone 4S、5的按钮大小和字体大小必须相同,iPhone 6和6+的按钮大小和字体大小必须不同。我如何在我的应用程序中实现这一点。我知道我们可以通过编程实现,但有没有机会在故事板上使用自适应布局实现呢 我使用的是xcode7.2,swift2Swift 如何为iphone4s、5设置相同的字体和按钮大小,为iPhone6和6+设置不同的字体和按钮大小;设备?,swift,storyboard,adaptive-layout,Swift,Storyboard,Adaptive Layout,我正在开发一个iOS应用程序,我观察了iPhone 5、6、6+的用户界面。每个设备的所有字体都不同,但我的要求是,iPhone 4S、5的按钮大小和字体大小必须相同,iPhone 6和6+的按钮大小和字体大小必须不同。我如何在我的应用程序中实现这一点。我知道我们可以通过编程实现,但有没有机会在故事板上使用自适应布局实现呢 我使用的是xcode7.2,swift2 提前感谢。我遇到了同样的问题,并用雨燕解决了它。 我创建了一个静态变量fontsize,根据屏幕的大小,该变量使用适当的fontsi
提前感谢。我遇到了同样的问题,并用雨燕解决了它。 我创建了一个静态变量fontsize,根据屏幕的大小,该变量使用适当的fontsize进行动态初始化
import UIKit
class ViewFunctions {
let screenSize = UIScreen.mainScreen().bounds.size
static var fontsize: CGFloat {
get {
if screenSize.height >= 1024 { // iPad Pro
return 16.0
} else if screenSize.height >= 768 { // iPad
return 16.0
} else if screenSize.height >= 414 { // iPhone 6Plus
return 15.0
} else if screenSize.height >= 375 { // iPhone 6/s
return 15.0
} else if screenSize.height >= 320 { // iPhone 5/s
return 14.0
} else if screenSize.height >= 319 { // iPhone 4/s
return 14.0
} else {
return 14.0
}
}
}
}
然后使用它设置按钮标签的字体大小:
import UIKit
class TestClass {
var testButton: UIButton = UIButton(type: UIButtonType.System) as UIButton!
testButton.titleLabel!.font = UIFont(name: "Helvetica Neue", size: ViewFunctions.fontsize)
testButton.setTitle("Test", forState: .Normal)
// add button to view or sth like that...
}
你检查过这个吗?我不明白“每个设备的所有字体都不同”,因为标准系统字体是相同的?