首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击时隐藏特定按钮

单击时隐藏特定按钮
EN

Stack Overflow用户
提问于 2015-11-30 10:09:49
回答 1查看 220关注 0票数 0
代码语言:javascript
复制
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)
    }

用一个对象编程创建按钮,我想在单击时隐藏特定的按钮。

提前谢谢..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-30 10:15:56

在您的按钮中,单击事件,根据您想要满足的条件隐藏按钮:

代码语言:javascript
复制
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
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33996020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档