您可以使用两种方法更改字体大小。
1.) 使用UISegmentControl
的appearance
代理更新字体。这将为您的应用程序中所有UISegmentContol
对象更新相同的属性。
您不需要在每个视图控制器中设置,只需在appDelegate
的didFinishLaunching:
中设置即可。
var attr = NSDictionary(object: UIFont(name: "yourFontName", size: 12.0)!, forKey: NSFontAttributeName)
UISegmentedControl.appearance().setTitleTextAttributes(attr, forState: .Normal)
2.) 更新特定分段控件的字体。
var attr = NSDictionary(object: UIFont(name: "yourFontName", size: 12.0)!, forKey: NSFontAttributeName)
self.statusSegmentControl.setTitleTextAttributes(attr, forState: .Normal)
yourSegControl.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "YourFont", size: 18.0)! ], forState: .Normal)
您可以在苹果文档中了解更多信息。
试试这个
var attributes = NSDictionary(object: UIFont(name: "HelveticaNeue", size: 12.0)!, forKey: NSFontAttributeName)
segmentControl.setTitleTextAttributes(attributes, forState: .Normal)