为任何宽度类大小设置分段控制字体

时间:2016-09-25 09:51:37

标签: ios swift

我只想增加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中增加字体

1 个答案:

答案 0 :(得分:1)

检查设备型号:

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)
}

代码可以更好。