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
//
//  Copyright © 2020 jm. All rights reserved.
//
 
import UIKit
 
@objc public extension UITextField {
    @objc func dh_inputAccessoryView() {
        let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: dh_screenWidth, height: 30.0))
        toolBar.isTranslucent = true;
        toolBar.barStyle = .default;
        let spaceItem = UIBarButtonItem.init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
        let button = UIButton(type: .custom)
        button.setTitle("完成", for: .normal)
        button.setTitleColor(UIColor.dhcolor_c0(), for: .normal)
        button.titleLabel?.font = UIFont.dhFont_f2()
        button.addTarget(self, action: #selector(doneAction), for: .touchUpInside)
        let doneItem = UIBarButtonItem(customView: button)
        toolBar.items = [spaceItem, doneItem]
        toolBar.barTintColor = UIColor.dhcolor_c3().withAlphaComponent(0.3)
        self.inputAccessoryView = toolBar
    }
    
    @objc fileprivate func doneAction() {
        self.resignFirstResponder()
    }
}