我可以向 UIToolbar 添加彩色按钮吗?
似乎我无法在 UIToolbar 中添加任何包含颜色的按钮,它们总是被替换为白色蒙版。如何将彩色图像添加到 UIToolbar 中的自定义按钮?
It seems like I can't add any buttons that contain colors in a UIToolbar, they always get replaced with a white mask. How can I add a colored image to a custom button in a UIToolbar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,你可以,但它并不是真正的 uibarbuttonitem。
这是链接。
http://fredandrandall.com/blog/2011 /03/31/how-to-the-color-of-a-uibarbuttonitem/
PS.
如果您希望该按钮有一个 IBAction,请在 valuechanged 事件上调用它。
Yes you can, but its not really a uibarbuttonitem.
here is the link.
http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/
PS.
If you want to have an IBAction for that button, then call it on valuechanged event.
不,我认为你不能直接这样做。看起来应该是像你说的那样。
您也许可以通过将图像放在工具栏的图像上并通过调整命中测试让触摸事件通过它来进行破解。
No, I dont think you can directly. It looks like it has to be as you said.
You might be able to hack things though by putting your image over the toolbar's image and letting the touch events pass through it by tweaking the hit testing.
如果不使用私有 API,则无法实现。如果您使用私有 API,Apple 会阻止您的应用程序,因此您不妨构建自己的控件并使用它。
Without using private API's, you can't. Apple will block your app if you use the private API's, so you might as well construct your own control and use that.
您还可以查看 UIApperance 协议,这对于自定义许多 UI 元素的外观和感觉非常有用。您可以使用静态方法更改特定项目或该项目的每个实例。
这会将应用程序中 UIToolBar 的每个实例更改为蓝色。
You can also look at the UIApperance protocol this is very useful for customising the look and feel of many of the UI elements. You can change a specific item or every instance of that item using the static method.
This would change every instance of a UIToolBar in your app blue.
您可以使用自定义工具栏,您可以在其中使用任何工具栏背景和彩色图像: http://github.com/ marichka/自定义 UIToolbar
You can use custom toolbar, where you can use any toolbar background and colored images: http://github.com/marichka/Custom-UIToolbar