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)
}
使用一个对象以编程方式创建按钮我希望在点击时隐藏特定按钮。
提前致谢...
答案 0 :(得分:1)
在按钮单击事件中,根据您要满足的条件隐藏按钮:
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
}
}