Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBOutlet weak var button_0: UIButton!
- @IBOutlet weak var button_1: UIButton!
- @IBOutlet weak var button_2: UIButton!
- @IBOutlet weak var button_3: UIButton!
- //...以下複数個続く
- var buttons:[UIButton] = []
- buttons.append(button_0)
- buttons.append(button_1)
- buttons.append(button_2)
- //...以下個数分続く
- for i in 0..<buttons.count{
- buttons[i].tag = i
- buttons[i].addTarget(self, action: #selector(ToolView.action(_:)), forControlEvents: .TouchUpInside)
- }
- @objc private func action(sender: UIButton){
- switch sender.tag {
- case 0:
- print("button_0")
- case 1:
- print("button_1")
- case 2:
- print("button_2")
- //...個数分続く
- default:break
- }
- }
- @IBAction func action(sender: UIButton) {
- switch sender.tag {
- case 0:
- print("button_0")
- case 1:
- print("button_1")
- case 2:
- print("button_2")
- //...個数分続く
- default:break
- }
- }
- @IBOutlet var buttons:[UIButton] = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement