UI can use control appearance, best place to add it is in app delegate, didFinishLaunchingWithOptions
method, use this if you want to set up the same attribute to every UISegmentedControls in your project just once:
let attr = NSDictionary(object: UIFont(name: "HelveticaNeue-Bold", size: 16.0)!, forKey: NSFontAttributeName)
UISegmentedControl.appearance().setTitleTextAttributes(attr as [NSObject : AnyObject] , forState: .Normal)
But if you are going to set up attributes to just one UISegmentedControl or if you want to change it more often base on some condition use this, UISegmentedControl method:
func setTitleTextAttributes(_ attributes: [NSObject : AnyObject]?,
forState state: UIControlState)
Example:
let attr = NSDictionary(object: UIFont(name: "HelveticaNeue-Bold", size: 16.0)!, forKey: NSFontAttributeName)
seg.setTitleTextAttributes(attr as [NSObject : AnyObject] , forState: .Normal)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…