更改 UISegmented 控制器字体

changing UISegmented controllers font

有谁知道如何更改自定义 UISegmented 控制器的字体。在代码中,IB 没有做我想用控制器做的所有其他事情!

我的代码是:

let items = ["Classic", "Cool Blue", "Safari", "Motors", "Old School"]
let customSC = UISegmentedControl(items: items)
customSC.selectedSegmentIndex = 3
customSC.frame = CGRectMake(ScreenWidth/2 - (ScreenWidth*0.342), ScreenHeight/2, (ScreenWidth*0.684), (ScreenHeight*0.085))
customSC.layer.cornerRadius = 5.0
customSC.backgroundColor = UIColor.clearColor()
customSC.tintColor = UIColor.whiteColor()
customSC.font // font doesn't exist.... 

// add the SC target action
customSC.addTarget(self, action: "changeScheme:", forControlEvents:.ValueChanged)
self.view.addSubview(customSC)

提前感谢任何可以提供帮助的人!

我想你要找的方法是:

func setTitleTextAttributes(_ attributes: [NSObject : AnyObject]?, forState state: UIControlState)

类似于:

let attrs = [NSFontAttributeName:UIFont(name: "AmericanTypewriter", size: 10.0)!]
customSC.setTitleTextAttributes(attrs, forState: UIControlState.Normal)