自定义UINavigationBar背景 [英] Custom UINavigationBar Background
问题描述
我一直在尝试为我的整个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屋!