如何改变leftbarbutton项的大小?

时间:2018-03-10 19:27:12

标签: swift uibarbuttonitem

我添加了一个左栏按钮图像,并像这样改变它的大小。

let homeButton = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
        homeButton.setBackgroundImage(#imageLiteral(resourceName: "splash-logo_iso"), for: .normal)
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: homeButton)

甚至机会宽度和高度,我的导航项看起来像这样。 我该如何改变尺寸?请问任何建议或示例代码?

我的导航项现在看起来像这样:

leftbarbuttonimage

1 个答案:

答案 0 :(得分:0)

我找到了这样的解决方案:

 let homeButton = UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
        homeButton.setBackgroundImage(#imageLiteral(resourceName: "splash-logo_iso"), for: .normal)
        //menu button custom view
        let leftView = UIView(frame: CGRect(x: 0,y: 0,width:24,height:24))
        leftView.addSubview(homeButton)

        //left uibarbutton
        let leftItem:UIBarButtonItem = UIBarButtonItem(customView: leftView)
        navigationItem.leftBarButtonItem = leftItem