像福克斯新闻 iPhone 应用程序一样自定义 UINavigationBar
如何进行 UINavigationBar 自定义?是使用子类化还是类别?
我对 2 个方面感兴趣:
- 将图像添加到导航栏(如 FOXNEWS 徽标)
- 自定义背面按钮到“显示”。 (后退按钮通常采用堆栈中上一个视图的标题,但上一个视图中没有标题。)
预先感谢您的帮助
How can the UINavigationBar customizations be done? Is it using subclassing or categories?
I am interested in 2 aspects:
- Adding an image to the NavBar (like the FOXNEWS logo)
- Customizing the back button to "Shows". (the back button usually takes the title of the previous view in the stack, but there is no title in previous view.)
Thanks in advance for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于福克斯新闻应用程序,看起来他们只是设置了导航栏的色调颜色。至于福克斯新闻徽标,它可能只是导航栏标题视图上的图像视图。此代码进入视图控制器的
viewDidLoad
方法:要自定义后退按钮,您需要将其放置在上一个视图控制器的
viewDidLoad
方法中(即该按钮返回的那个):如果您想为应用程序的导航栏使用完全自定义的背景图像,则需要创建一个自定义
UINavigationBar
类别并在其UINavigationBar
中绘制图像。代码>drawRect:方法。像这样的东西:For the Fox News app it looks like they just set the tint color of the navigation bar. As for the Fox News logo, it's probably just an image view on the title view of the navigation bar. This code goes into a view controller's
viewDidLoad
method:To customize the back button you need to place this in the
viewDidLoad
method of the previous view controller (i.e. the one that this button leads back to):If you want to use a totally custom background image for your application's navigation bar, you need to create a custom
UINavigationBar
category and draw the image within itsdrawRect:
method. Something like this:将图像添加到导航栏使用此代码
为 UINavigationBar 创建类别
adding image to navigation bar use this code
create category for UINavigationBar