自定义 UINavigationBar 背景 [英] Custom UINavigationBar Background

查看:37
本文介绍了自定义 UINavigationBar 背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试为整个 NavigationBar(不仅仅是 titleView)设置自定义背景,但一直在努力.

I've been trying to set up a custom background for the whole of my NavigationBar (not just the titleView) but have been struggling.

我找到了这个话题

http://discussions.apple.com/thread.jspa?threadID=1649012&tstart=0

但我不确定如何实现给出的代码片段.代码是作为新类实现的吗?另外,我在哪里设置 UINavigationController,因为我有一个使用 NavigationView 模板构建的应用程序,所以它没有按照示例在我的根控制器中完成

But am not sure how to implement the code snippet that is given. Is the code implemented as a new class? Also where do I instatiate the UINavigationController as I have an application built with the NavigationView template so it is not done in my root controller as per the example

推荐答案

你只需要像这样重载 drawRect :

You just have to overload drawRect like that :

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

这篇关于自定义 UINavigationBar 背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆