ikbal
ikbal

Reputation: 1174

Hide particular button on click

for(i=0; i<randomString.length; i++) {
        btn = UIButton()
        btn.frame = CGRectMake(width-10, 45, 40, 40)
        print(width)
        print(ArrFinalstring)
        btn.tag = i
        btn.layer.cornerRadius = 0.5 * btn.bounds.size.width
         btn.setTitle(ArrFinalstring.objectAtIndex(i) forState: UIControlState.Normal)
        btn.titleLabel!.textAlignment = .Center
        btn.addTarget(self, action: "button_click:", forControlEvents: UIControlEvents.TouchUpInside)
        width = width + 50
        if(i > 5) {
            if(i == 6) {
                width = 30
            }
            btn.frame = CGRectMake(width-10, 95, 40, 40)
            width = width + 0
        }
        if(i > 11) {
            if(i == 12) {
                width = 50
            }
            btn.frame = CGRectMake(width-10, 145, 40, 40)
            width = width + 0
        }
        viewButton.addSubview(btn)
    }

Create button programmetically with one object i want to hide particular button on click.

Thanks in advance...

Upvotes: 0

Views: 222

Answers (1)

Greg
Greg

Reputation: 25459

In your button click event hide the button base on the condition you want to be meet:

func button_click(sender: UIButton) {
    // I don't know which button you want to hide.
    // Just put your logic here and hide the particular one

    // That's example how you can hide button with tag equals 1
    // I believe you want to use tags because you set them up in the method you showed above
    if let btn = view.viewWithTag(1) as? UIButton {
        btn.hidden = true
    }

    // Or if you what to hide the pressed button where tag is equal one you can do:
    if sender.tag == 1 {
        sender.hidden = true
    }
}

Upvotes: 1

Related Questions