UIBarButtonItem+Extensions.swift 935 B

123456789101112131415161718192021222324252627
  1. //
  2. // UIBarButtonItem+Extensions.swift
  3. // WeiBo
  4. //
  5. // Created by Handy_Cao on 2018/4/8.
  6. // Copyright © 2018年 Handy_Cao. All rights reserved.
  7. //
  8. import UIKit
  9. extension UIBarButtonItem {
  10. /// 便利构造方法,自定义 UIBarButtonItem
  11. ///
  12. /// - Parameters:
  13. /// - title: 标题
  14. /// - fontSize: 标题大小
  15. /// - normalColor: 正常状态颜色
  16. /// - highlightedColor: 点击状态颜色
  17. /// - target: 目标控制器
  18. /// - action: 点击实现的方法
  19. convenience init(title: String, fontSize: CGFloat = 16,normalColor: UIColor = UIColor.white, highlightedColor: UIColor = UIColor.white,target: AnyObject?,action: Selector){
  20. let btn:UIButton = UIButton(title: title, fontSize: fontSize, normalColor: normalColor, highlightedColor: highlightedColor)
  21. btn.addTarget(target, action: action, for: .touchUpInside)
  22. self.init(customView: btn)
  23. }
  24. }