iOS: setting Exclusive Touch to all buttons in a view

后端 未结 8 451
灰色年华
灰色年华 2021-01-03 16:17

My app has many buttons in a Window and I want to set Exclusive Touch all of them together. Do you have any suggestion about this? Thanks

相关标签:
8条回答
  • 2021-01-03 17:21

    If you are adding buttons pragmatically, then send a message to the button [button setExclusiveTouch:YES]; for each buttons before adding to its super view. Else if you are using xib, you have to send the same message to the button in viewDidLoad or in loadView.

    0 讨论(0)
  • 2021-01-03 17:23

    Here is some code in swift that will set exclusive touch to all buttons in your viewcontroller's view

    for button in self.view.subviews {
        if(button.isKindOfClass(UIButton)){
            (button as! UIButton).exclusiveTouch = true
        }
    }
    
    0 讨论(0)
提交回复
热议问题