JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
//  SMBBroadsideButton.swift
//  DHBaseModule
//
//  Created by imou on 2020/4/23.
//  Copyright © 2020 jm. All rights reserved.
//
 
import UIKit
 
@objc public class SMBBroadsideButton: UIButton {
    public typealias SMBBroadsideButtonClickBlock = (_ button: SMBBroadsideButton) -> Void
    private var _clickBlock: SMBBroadsideButtonClickBlock!
 
    public override init(frame: CGRect) {
        super.init(frame: frame)
        
    }
 
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    @objc public func clickResult(clickBlock: @escaping SMBBroadsideButtonClickBlock) -> SMBBroadsideButton {
        _clickBlock = clickBlock
        addTarget(self, action: #selector(btnClick(btn:)), for: .touchUpInside)
        return self
    }
 
 
    @objc public func title(title: String, state: UIControlState) -> SMBBroadsideButton {
        setTitle(title, for: state)
 
        return self
    }
 
    @objc public func image(image: String, state: UIControlState) -> SMBBroadsideButton {
        setImage(UIImage(named: image)!, for: state)
        return self
    }
 
    // MARK: - Private Methods
 
    public override func didMoveToSuperview() {
        super.didMoveToSuperview()
        configureView()
    }
    private func configureView() {
        backgroundColor = .dhcolor_c2()
        titleLabel?.font = UIFont.dhFont_t7()
        setTitleColor(.dhcolor_c0(), for: .normal)
        setCornerRadius(corners: [.topRight, .bottomRight], radius: dh_height / 2.0)
        self.setUIButtonImageRightWithTitleLeftUI()
    }
 
    func showBtn() {
        
    }
 
    func dismissBtn() {
    }
 
    // MARK: - Action Methods
 
    @objc func btnClick(btn: SMBBroadsideButton) {
        if _clickBlock != nil {
            _clickBlock(btn)
        }
    }
}