宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
//
//  UIBarButtonItem+Extensions.swift
//  THProject
//
//  Created by alvin_y on 2018/3/27.
//  Copyright © 2018年 yang-wang. All rights reserved.
//
import UIKit
 
extension UIBarButtonItem {
    
    
    /// 创建一个默认的按钮
    /// - Parameters:
    ///   - image: 图片
    ///   - title: 文字
    ///   - target: target
    ///   - alignment: UIControl.ContentHorizontalAlignment
    ///   - action: Selector
    class func yy_creat(image:UIImage,title:String = "", target: Any?, alignment: UIControl.ContentHorizontalAlignment, action: Selector) -> (item:UIBarButtonItem, btn:UIButton) {
        let btn = UIButton.init(type: .custom)
        btn.setImage(image, for: .normal)
        btn.setTitle(title, for: .normal)
        btn.addTarget(target, action: action, for: .touchUpInside)
        btn.bounds = CGRect.init(x: 0, y: 0, width: 30, height: 50)
        btn.contentHorizontalAlignment = alignment == .left ? .left : .right
        return (item:self.init(customView: btn), btn:btn)
    }
    
    
    /// 创建一个指定字号大小&颜色的按钮
    /// - Parameters:
    ///   - title: 文字
    ///   - font: 字体
    ///   - color: 颜色
    ///   - target: target
    ///   - action: Selector
    class func yy_creat(title:String, _ font: UIFont = UIFont.systemFont(ofSize: 14), _ color:UIColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1), target:Any?, action:Selector) -> (item:UIBarButtonItem, btn:UIButton) {
        let btn = UIButton.init(type: .custom)
        btn.setTitle(title, for: .normal)
        btn.titleLabel?.font = font
        btn.setTitleColor(color, for: .normal)
        btn.addTarget(target, action: action, for: .touchUpInside)
        btn.sizeToFit()
        return (item:self.init(customView: btn), btn:btn)
    }
   
    
}