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...

Answers


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
    }
}

Need Your Help

libgdx- pixmap: can I somehow change the width of the line?

java width libgdx pixmap

I want to draw a line and then generate a texture (with libgdx). I found out that creating a texture from circles, rectangles and lines is simple with pixmap.

How to require CheckedListBox to have at least one item selected

vb.net winforms visual-studio-2005

With the CheckListBox in VB.NET in VS2005, how would you make it compulsory that at least one item is selected?