Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. @IBOutlet weak var button_0: UIButton!
  2. @IBOutlet weak var button_1: UIButton!
  3. @IBOutlet weak var button_2: UIButton!
  4. @IBOutlet weak var button_3: UIButton!
  5. //...以下複数個続く
  6.  
  7. var buttons:[UIButton] = []
  8.  
  9. buttons.append(button_0)
  10. buttons.append(button_1)
  11. buttons.append(button_2)
  12. //...以下個数分続く
  13. for i in 0..<buttons.count{
  14. buttons[i].tag = i
  15. buttons[i].addTarget(self, action: #selector(ToolView.action(_:)), forControlEvents: .TouchUpInside)
  16. }
  17.  
  18. @objc private func action(sender: UIButton){
  19. switch sender.tag {
  20. case 0:
  21. print("button_0")
  22. case 1:
  23. print("button_1")
  24. case 2:
  25. print("button_2")
  26. //...個数分続く
  27. default:break
  28. }
  29. }
  30.  
  31. @IBAction func action(sender: UIButton) {
  32. switch sender.tag {
  33. case 0:
  34. print("button_0")
  35. case 1:
  36. print("button_1")
  37. case 2:
  38. print("button_2")
  39. //...個数分続く
  40. default:break
  41. }
  42. }
  43.  
  44. @IBOutlet var buttons:[UIButton] = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement