2019-11-05

解决自定义导航栏左侧按钮图标变形问题

1.创建底图View

2.把button添加到底图上

3.创建UIbarbuttonitem,customView =  底图view

4.设置导航栏的左侧item = 3


自定义导航栏

func setupNaviBarAnoutNextVc(nextVc:UIViewController,namePoor:String,poorBackSelector:Selector) {

//设置导航栏颜色

nextVc.navigationController?.navigationBar.barTintColor = .white


nextVc.navigationController?.navigationBar.isHidden = false

//导航栏阴影线的设置

nextVc.navigationController?.navigationBar.shadowImage = UIImage.init()

//穿透效果设置

nextVc.navigationController?.navigationBar.isTranslucent = false

let rootNaviitemColor =UIColor.darkGray

let fontSize =UIFont.systemFont(ofSize:19)

//title 属性

nextVc.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:rootNaviitemColor,NSAttributedString.Key.font : fontSize]

nextVc.navigationItem.title= namePoor

//解决导航栏leftbarbutton图片变形问题

let customBtn =UIButton.init(type: .custom)

customBtn.frame=  CGRect.init(x:-5, y:0, width:44, height:44)

customBtn.addTarget(nextVc, action:poorBackSelector, for: .touchUpInside)

customBtn.setBackgroundImage(UIImage.init(named:"goback"), for:.normal)

let leftv =UIView.init(frame:CGRect.init(x:0, y:0, width:50, height:44))

leftv.addSubview(customBtn)

let lop =UIBarButtonItem.init(customView:leftv)

nextVc.navigationItem.leftBarButtonItem = lop

}

你可能感兴趣的:(2019-11-05)