我只想增加 iPad 的字体大小,所以我使用了以下内容
let attr = NSDictionary(object: UIFont(name: "HelveticaNeue-Bold", size: 16.0)!, forKey: NSFontAttributeName as NSCopying)
并且在 viewDidLoad()
segmentedControl.setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)
但这会增加 iPhone 和 iPad 的字体。我想知道如何只增加 iPad 的字体
最佳答案
查看设备型号:
let model = UIDevice.currentDevice().model
if model == "iPad" {
let attr = NSDictionary(object: UIFont(name: "HelveticaNeue-Bold", size: 16.0)!, forKey: NSFontAttributeName as NSCopying)
segmentedControl.setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)
}else{
let attr = NSDictionary(object: UIFont(name: "HelveticaNeue", size: 16.0)!, forKey: NSFontAttributeName as NSCopying)
segmentedControl.setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)
}
代码可以更好。
关于ios - 为任何宽度类大小设置分段控制字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39685523/