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

标签 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 的字体

最佳答案

查看设备型号:

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/

相关文章:

iphone - 仅在 iPad(模拟器或设备)上崩溃 - [__NSArrayM insertObject :atIndex:]

iphone - 如何解析 XML 的多个属性?

swift - 动画后如何去除SKTexure

swift - 为什么这个快速按钮设置会崩溃?

ios - 无法在 segue 中取消选中 UITableViewCell

ios - 如何在 UISearchBar iOS 11 中居中占位符文本

ios - UITableView 单元格不显示所有数据

ios - AVAudioPlayer 为路径 Swift 3 xcode 8.0 提供 nill

swift - 调用 "strategy design pattern"中的方法时缺少参数标签 -SWIFT

ios - 在 subview 中添加 UIViewController