【发布时间】:2012-06-15 04:44:29
【问题描述】:
我正在使用 UINavigation 控制器在 xCode 4.3.2 中创建一个 tabBar 应用程序。我在 AppDelegate 中使用以下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:
[[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease], viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
现在的问题是我想在导航栏中自定义背景图像。我找到的解决方案是编写 UINavigationBar 的子类并在界面生成器中设置新的子类。但就我而言,我正在以编程方式设置导航控制器,那么如何实现呢? 我也尝试过将类别创建为
@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
但它根本不起作用。
【问题讨论】:
-
您要设置标签栏或导航栏的背景图片。您的问题标题与导航栏有关,并且您发布了标签栏的代码???
-
Mitesh Khatri,我想设置导航栏的背景图像,我发布了代码来展示我如何添加导航控制器。我尝试将navigationBar 子类化,但我不知道如何将navigatioBar 类设置为我的新子类,因为我正在以编程方式进行所有操作。谢谢等待您的回复
-
你可以在stackoverflow.com/questions/9386633/…看到我的帖子
标签: iphone uinavigationcontroller uinavigationbar xcode4.3