UIBarButtonItem+item.swift 677 B

1234567891011121314151617181920212223
  1. //
  2. // UIBarButtonItem+item.swift
  3. // SolarStationSwift
  4. //
  5. // Created by weclouds on 2018/8/9.
  6. // Copyright © 2018年 weclouds. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. extension UIBarButtonItem{
  11. class func createBarbuttonItem(image:String,highImage:String,target:Any?,action:Selector) ->UIBarButtonItem{
  12. let item = UIButton()
  13. item.setImage(UIImage(named: image), for: .normal)
  14. item.setImage(UIImage(named: highImage), for: .highlighted)
  15. //自适应大小
  16. item.sizeToFit()
  17. item.addTarget(target, action: action, for: UIControl.Event.touchUpInside)
  18. return UIBarButtonItem(customView: item)
  19. }
  20. }