我们如何更改UISegmentControl的以下属性:字体,边框,颜色 . 我需要UISegementControl如下所示:
用了一小时的谷歌搜索,但没有找到任何正确的答案 . 请指导 .
以下是我到目前为止尝试的内容:
override func viewDidLayoutSubviews() {
self.segmentTimes = UISegmentedControl.appearance()
self.segmentTimes.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.black], for: UIControlState.normal)
self.segmentTimes.tintColor = UIColor.black
let attr = NSDictionary(object: UIFont(name: "Sans-Regular", size: 14.0)!, forKey: NSFontAttributeName as NSCopying)
self.segmentTimes.setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)
self.segmentDuration.setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)
self.segmentSeverity.setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)
self.segmentCharacter.setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)
self.segmentDurationType.setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)
}
我到目前为止管理得像这样:
1 回答
Please create a custom UIControl as follows which works for Swift 3 Xcode 8/9 and tweak the segment creation width according to text-width