2016-06-21 2 views
0

세 개의 세그먼트가있는이 UISegmentControl을 가지고 있으며 그 중 하나를 누르면 강조 표시됩니다. 그런 다음 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 
    } 

답변

0

같습니다 다음 (colorIndex)) 및과 같이 대신에 값으로 세그먼트 제어를 설정 :

customSC.selectedSegmentIndex = colorIndex 

가 서식하지만 떨어져 보이는, 어쩌면 당신은 자세한 내용을 제공 할 수있다.

관련 문제