如何将自定义 NOT TINTED 图像添加到 UIBarButtonItem
How to add custom NOT TINTED image to UIBarButtonItem
我想向 UIBarButtonItem 添加图像。
我的代码:
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 的左侧(不是栏按钮只是图像)?
谢谢
UIBarButtonItem
中的默认图像渲染案例是 UIImageRenderingMode.AlwaysTemplate
。因此,您必须使用 UIImageRenderingMode.AlwaysOriginal
的渲染选项创建一个图像,并将该图像设置为 UIBarButtonItem
。所以:
let customImage = UIImage(named: "icon1")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let button1 = UIBarButtonItem(image: customImage, style: .Plain, target: self, action: "Onb1ClickListener")
我想向 UIBarButtonItem 添加图像。
我的代码:
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 的左侧(不是栏按钮只是图像)?
谢谢
UIBarButtonItem
中的默认图像渲染案例是 UIImageRenderingMode.AlwaysTemplate
。因此,您必须使用 UIImageRenderingMode.AlwaysOriginal
的渲染选项创建一个图像,并将该图像设置为 UIBarButtonItem
。所以:
let customImage = UIImage(named: "icon1")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let button1 = UIBarButtonItem(image: customImage, style: .Plain, target: self, action: "Onb1ClickListener")