Swift 更改UI分段控制器字体
有人知道如何更改自定义UI分段控制器的字体吗。在代码中,作为IB,我不想用控制器做所有其他事情 我的密码是:Swift 更改UI分段控制器字体,swift,uisegmentedcontrol,Swift,Uisegmentedcontrol,有人知道如何更改自定义UI分段控制器的字体吗。在代码中,作为IB,我不想用控制器做所有其他事情 我的密码是: let items = ["Classic", "Cool Blue", "Safari", "Motors", "Old School"] let customSC = UISegmentedControl(items: items) customSC.selectedSegmentIndex = 3 customSC.frame = CGRectMake(ScreenWidth/2
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)
非常感谢你的自由。我一直在尝试该版本,但它只会使分段控制器完全消失-(感谢自由。出于某种原因,我在分段控制器上的动画隐藏了它。现在它工作得很好。非常感谢。