gpt4 book ai didi

ios - 如何在 Swift 中更改 UISegmentedControl 的选定段 tintColor

转载 作者:搜寻专家 更新时间:2023-10-31 08:16:17 24 4
gpt4 key购买 nike

我想在 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
//

}

}

谢谢!

最佳答案

在 ios 13 以上使用下面的代码,

if #available(iOS 13.0, *) {
segment.selectedSegmentTintColor = .red
} else {
segment.tintColor = .red
}

关于ios - 如何在 Swift 中更改 UISegmentedControl 的选定段 tintColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41544625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com