删除 UINavigationBar 中按钮的发光效果
如何消除导航栏上按钮的光泽/光泽效果? 如果我使用自定义图像自定义导航栏,按钮不会受到影响,我可以删除它们的效果(线条和光泽),或者为整个按钮定义十六进制颜色代码,甚至也为它们定义自定义图像?
How can I remove the gloss/shine effect from the buttons on navigation bars?
If I customize the navigation bar by using a custom image the buttons are not affected, can I remove the effect from them (the line and glossing), or define a hex color code for the whole button, or even a custom image for them too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚经历了解决这个问题的过程。基本上,您需要创建自定义可拉伸图像并将它们用作按钮的背景以消除光泽。替换 UINavigationController 中的后退按钮有点困难。为此,我使用 UINavigationControllerDelegate 将默认后退按钮替换为我的自定义按钮。
下面是一些代码:
在 UIBarButtonItem 上创建一个类别来创建自定义按钮。这是我的。我使用此类别来自定义常规栏按钮和后退按钮:
将按钮添加到您的 UINavigationBar
如果您还想替换 UINavigationController 的后退按钮,请设置 UINavigationControllerDelegate 并实现 willShowViewController 方法,如下所示:
这是我正在使用的可拉伸图像:
I just went through the process of figuring this out. Basically, you need to create custom stretchable images and use them as the button's background to get rid of the shine. Replacing the back buttons in a UINavigationController is a bit tougher. For that I used a UINavigationControllerDelegate to replace the default back button with my custom button.
Here's some code:
Create a category on UIBarButtonItem that creates your custom button. Here's mine. I use this category to customize both regular bar buttons and back buttons:
Add the button to your UINavigationBar
If you also want to replace the UINavigationController's back buttons, setup a UINavigationControllerDelegate and implement the willShowViewController method like so:
Here are the stretchable images I'm using:
要更改后退按钮,无需实现委托方法 uinavigationcontroller。
在设置所需的后退按钮后,您只需将 hidesBAckButton 属性设置为 YES,正如 @Justin Gallacher 完美解释的那样。
For changing the back button it is not necessary to implement the delegate method uinavigationcontroller.
You only need set the hidesBAckButton property to YES after setting the desired backbutton as @Justin Gallacher explained perfectly.
您必须使用带有图像的自定义按钮,而不会在图像上产生任何光泽效果,这样您就可以消除导航栏中按钮的光泽效果。
you have to use the custom button with images without any gloss effect on the images by which you can get rid of the gloos effect of the button from navbar.