2015-11-30 3 views
0
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

написать код для '' button_click. – amorbytes

ответ

0

В вашем случае нажатия кнопки скрыть кнопку базы на состоянии вы хотите быть встречайте:

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 
    } 
} 
Смежные вопросы