Swift 4.2 with the goal
extension UIBarButtonItem { convenience init(image :UIImage, title :String, target: Any?, action: Selector?) { let button = UIButton(type: .custom) button.setImage(image, for: .normal) button.setTitle(title, for: .normal) button.frame = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) if let target = target, let action = action { button.addTarget(target, action: action, for: .touchUpInside) } self.init(customView: button) } }
abbood Jan 28 '19 at 13:59 2019-01-28 13:59
source share