【发布时间】:2017-05-23 12:19:55
【问题描述】:
我想在 Swift 3 中更改 UISegmentedControl 选定段的 tintColor。
我在 Objective-c 中搜索了很多答案...
这是我的代码:
class ViewController:UIViewController{
var segment:UISegmentedControl
override func viewDidLoad() {
super.viewDidLoad()
segment.insertSegment(withTitle: "AAA", at: 0, animated: true)
segment.insertSegment(withTitle: "BBB", at: 1, animated: true)
segment.insertSegment(withTitle: "CCC", at: 2, animated: true)
segment.addTarget(self, action: #selector(changeValue), for: .valueChanged)
segment.selectedSegmentIndex = 0
view.addSubview(segment)
}
func changeValue(sender:AnyObject) {
//I don't know how to do that change color when segment selected
//
}
}
谢谢!
【问题讨论】:
-
这里有一篇漂亮的文章来自定义segmentedControl :) smnh.me/customizing-appearance-of-uisegmentedcontrol 我相信你将不得不子类化 UISegmentedControl 来改变各种状态的背景图片:)
-
@imbeginner_sorry 请检查我的答案并回复..
-
只需向 UISegmentControl 添加 tint 颜色,如:segment.tintColor = UIColor.green
-
请查看答案并回复!
标签: ios iphone swift uisegmentedcontrol