我有一个 iPhone 应用程序使用UINavigationController
并希望使用自定义背景图像自定义元素。我能够为UINavigationController's
UINavigationBar
使用 Objective-C 类别很容易,如下所示:
http://foobarpig.com/iphone/uinavigationbar-with-solid-color-or-image-background.html http://foobarpig.com/iphone/uinavigationbar-with-solid-color-or-image-background.html
我想为UINavigationController's
UIToolbar
,但同样的方法似乎不起作用(尽管我完全不知道为什么不可行。)我环顾四周,人们似乎建议子类化UIToolbar
,但这对于UINavigationController's
工具栏,这是一个只读的UIToolbar
。我想使用UINavigationController's
工具栏而不是仅仅制作子视图工具栏,因为我使用的是滑入式工具栏setToolbarHidden
动画片。
任何人都知道是否可以将背景图像应用到此UINavigationController
工具栏(很可能通过某种方式覆盖drawRect
方法)?
Update:
在 iOS 5.0+ 中,您现在可以使用UIAppearance
自定义导航栏。
另一种方法是简单地为您的应用程序创建一个类别UINavigationBar
班级。实现起来非常简单:
界面:
@interface UINavigationBar (TENavigationBar)
- (void) drawRect:(CGRect)rect;
@end
执行:
@implementation UINavigationBar (TENavigationBar)
- (void) drawRect:(CGRect)rect
{
UIImage *image = [UIImage imageNamed:@"navigation_background"];
[image drawInRect:CGRectMake(0,
0,
self.frame.size.width,
self.frame.size.height)];
}
@end
那么这将是globally应用于你所有的UINavigationBar
是自动的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)