0
私はこの3つのセグメントを持つUISegmentControlを持っています。そのうちの1つを押してハイライトします。次に、ボタンを押してUISegmentControlを非表示にします。そして、私がUISegmentControlに戻ると、最後に押されたセグメントは強調表示されなくなります。どのように私はそれを修正するだろうか?UISegmentControlで最後に触れたセグメントをSwiftでハイライトさせるにはどうすればよいですか?
customSC.selectedSegmentIndex = 0
あなたはあなたのゲームに保管し、この値の設定でそれを呼び出すことができ(すなわちpressSettingsButton:あなたが0にあなたがpressSettingsButton呼び出すたびに、あなたのセグメント化されたコントロールを設定しているよう
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
}