Development record of developer who study hard everyday.

, ,

How to add click action on UIButton in iOS

 How to add click action on UIButton in iOS

iOS blog

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    private lazy var setBtn: UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: #selector(setBtnTap), for: .touchUpInside)
        return btn
    }()
    
    @objc
    func setBtnTap() {
        print("setBtnTap")
    }
 
    private lazy var setBtn: UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: #selector(setBtnTap(_:)), for: .touchUpInside)
        return btn
    }()
 
 
    @objc
    func setBtnTap(_ sender: UIButton) {
        print("setBtnTap")
    }
cs

1~10th line: This is the case you don't need to get button you clicked

12~22th line: This is the case you need to get button you clicked

Share:
Location: 대한민국 서울특별시

댓글 없음:

댓글 쓰기