Array of UIButtons in Swift 4

后端 未结 2 560
名媛妹妹
名媛妹妹 2021-01-14 04:52

I\'ve made a series of checkboxes in UiKit with UIButtons:

@IBOutlet weak var Box1: UIButton!
@IBOutlet weak var Box2: UIButton!
@IBOutlet weak var Box3: UIB         


        
2条回答
  •  暖寄归人
    2021-01-14 05:43

    I have created array of checkboxes(buttons) along with text(labels). You can select and deselect any button.

    func addCheckBoxButtonsForSecondContainerView ()
    {
        var xPosition = 0
        var yPosition = 0
        for i in 0..

    //Next we see here action for the buttons(checkboxes)

     @objc func secondViewButtonAction(_ sender: UIButton)
       {
        if arrayofSelectedIndexes.contains(sender.tag)
        {
            for i in 0..

    }

    //this is for title label action

     @objc func secondViewLabelAction(_ sender: UITapGestureRecognizer)
          {
            for subview in self.secondContainerView.subviews {
                if let button = subview as? UIButton {
                    let searchlbl:UILabel = (sender.view as! UILabel) //just to get sender tag
                    if searchlbl.tag == subview.tag
                    {
                        if arrayofSelectedIndexes.contains(searchlbl.tag)
                        {
                            for i in 0..

    Let me know if you need more clarification. User can click on button or title label. Same action will be performed. I'm attaching the screenshot here for output. [1]: https://i.stack.imgur.com/cXoww.png

提交回复
热议问题