Ios 如何将自定义非着色图像添加到UIBarButtonItem

Ios 如何将自定义非着色图像添加到UIBarButtonItem,ios,swift,uinavigationbar,uibarbuttonitem,Ios,Swift,Uinavigationbar,Uibarbuttonitem,我想给UIBarbuttonite添加一个图像 我的代码: let button1 = UIBarButtonItem(image: UIImage(named: "icon1"), style: .Plain, target: self, action: "Onb1ClickListener") let button2 = UIBarButtonItem(image: UIImage(named: "icon2"), style: .Plain, target: sel

我想给UIBarbuttonite添加一个图像

我的代码:

        let button1 = UIBarButtonItem(image: UIImage(named: "icon1"), style: .Plain, target: self, action: "Onb1ClickListener")
    let button2 = UIBarButtonItem(image: UIImage(named: "icon2"), style: .Plain, target: self, action: "Onb2ClickListener")
    let button3 = UIBarButtonItem(image: UIImage(named: "icon3"), style: .Plain, target: self, action: "Onb3ClickListener")

    self.navigationItem.setRightBarButtonItems([button1, button2, button3], animated: false)
    self.navigationItem.setHidesBackButton(true, animated: false)
  • 这是可行的,但我得到了着色的蓝色图像。如何使原始图像不着色

  • 如何将图像添加到UINavigationBar的左侧(不是bar按钮,只是图像)


  • 谢谢

    UIBarButtonItem
    中默认的图像渲染情况是
    UIImageRenderingMode.AlwaysTemplate
    。因此,您必须使用
    UIImageRenderingMode.AlwaysOriginal
    的渲染选项创建图像,并将该图像设置为
    uiBarButtonim
    。因此:

    let customImage = UIImage(named: "icon1")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    let button1 = UIBarButtonItem(image: customImage, style: .Plain, target: self, action: "Onb1ClickListener")
    

    谢谢,你知道我第二个问题的答案吗?我想你不能只在导航栏中添加一个图像而不进行黑客攻击,我会将它设置为一个带有图像的uibarbuttonite,但没有真正的功能。