gpt4 book ai didi

xcode - 如何在 Swift 中突出显示分段控制中最后触摸的段?

转载 作者:行者123 更新时间:2023-11-30 13:19:09 24 4
gpt4 key购买 nike

我有一个包含三个段的 UISegmentControl,我按下其中一个段,它会突出显示。然后,我按下一个按钮来隐藏 UISegmentControl,当我返回到 UISegmentControl 时,我按下的最后一段不再突出显示。我该如何解决这个问题?

func pressSettingsButton() {

var customSC = UISegmentedControl()
let items = ["blue", "orange", "red"]

customSC = UISegmentedControl(items: items)
customSC.selectedSegmentIndex = 0
customSC.frame = (CGRectMake(self.view!.bounds.width/2 - 540/2, 65 * scaleFactor, 250, 30))

customSC.layer.cornerRadius = 5.0
customSC.backgroundColor = UIColor.blackColor()
customSC.tintColor = UIColor.whiteColor()
customSC.addTarget(self, action: #selector(GameScene.changeColor(_:)), forControlEvents: .ValueChanged)
self.view!.addSubview(customSC)
}

if node.name == "settings" {
//shows UISegmentControl

pressSettingsButton()
}


if node.name == "closesettings" {
//close segment control

customSC.hidden = true
}

最佳答案

看起来您每次调用 pressSettingsButton 时都将分段控件设置为 0:

customSC.selectedSegmentIndex = 0

您可以使用存储在游戏中的该值的设置来调用它(即 pressSettingsButton(colorIndex)),然后将分段控件设置为该值,如下所示:

customSC.selectedSegmentIndex = colorIndex

但是格式看起来不对,所以也许您可以提供更多详细信息。

关于xcode - 如何在 Swift 中突出显示分段控制中最后触摸的段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37934200/

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