我使用UIImage
的默认UIButton
属性来设置背面图像。我已经成功完成了它,但似乎image
看起来很小。如何在UIButton
?
let viewForNavigation = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 40))
viewForNavigation.backgroundColor = UIColor.clear
let backbutton = UIButton(frame: CGRect(x: 0, y: 8, width: 320, height: 20))
backbutton.setImage(UIImage(named: "back_button"), for: UIControlState.normal)
backbutton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right:10)
backbutton.contentHorizontalAlignment = .left
backbutton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
backbutton.titleLabel!.font = UIFont().robotoMedium(withFontSize: 20)
backbutton.setTitle(title, for: .normal)
backbutton.setTitleColor(UIColor.black, for: UIControlState.normal)
backbutton.addTarget(self, action: #selector(exitViewController), for: UIControlEvents.touchUpInside)
viewForNavigation.addSubview(backbutton)
let rightBarButton = UIBarButtonItem(customView: viewForNavigation)
self.navigationItem.leftBarButtonItem = rightBarButton