2016-06-21 17 views
0

我有这个UISegmentControl三段,我按其中之一,它突出显示。然后我按下一个按钮来隐藏UISegmentControl,当我回到UISegmentControl时,我按下的最后一个段不再被高亮显示。我将如何解决这个问题?如何让UISegmentControl中的最后一个被触摸的段在Swift中高亮显示?

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 
    } 

回答

0

它看起来像你每次调用pressSettingsButton时间设置你的分段控制,以0:

customSC.selectedSegmentIndex = 0 

你可以与你在你的游戏中存储该值的设置调用它(即pressSettingsButton (colorIndex)),然后设置分段控制该值,而不是像这样:但是

customSC.selectedSegmentIndex = colorIndex 

的格式看起来了,所以也许你可以提供更多的细节。

相关问题