iphone - 将自定义 UINavigationBar 与 initAsRootViewController 一起使用 :

标签 iphone ios uinavigationbar uinavigationcontroller

我目前正在做以下事情:

    BlogViewController *viewController = [[BlogViewController alloc] initWithBlogPosts];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
    [self presentModalViewController:navController animated:YES];
    [viewController release];
    [navController release];

但是,我需要一种方法来使用自定义 UINavigationBar。我试过使用这样的类别:

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

但它似乎并没有意识到这一点。有什么建议么? BlogViewController 是 UIViewController 的子类。

最佳答案

对于 ios5,您可以直接使用 setBackgroundImage:forBarMetrics: 设置背景图像。

保留 ios5 之前的类别实现,并检查导航栏是否响应上面的选择器,并且您已经涵盖了两个版本。

关于iphone - 将自定义 UINavigationBar 与 initAsRootViewController 一起使用 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8196599/

相关文章:

iphone - UINavigationBar 使用动画更改色调颜色

ios - 如何使用 hitTest :withEvent: to send touches from my nav bar to the underlying view under certain circumstances?

iphone - 如何知道何时使用 Default.png 从头开始​​启动应用程序?

iphone - AudioQueue 捕获并返回不同的缓冲区大小

ios - 是否可以从 didTapOverlay 方法更改 GMSPolygon fillColor?

ios - Swift ios Firebase 不返回任何数据

iphone - 有没有办法使用 xcode/iphone sim 模拟多个 iphone?

iphone - 访问未知的setter方法

ios - 如何为 Storyboard中按钮名称的文本设置不同的字体大小

swift - 如何在 NavigationBar 上动态添加按钮(在运行时)? - swift 2.0