【问题标题】:change navigationbar on only one view仅在一个视图上更改导航栏
【发布时间】:2013-02-11 13:20:39
【问题描述】:

我在我的 appdelegate 中设置了一个自定义导航栏。您可以在此处查看代码。

UIImage *image = [UIImage imageNamed:@"navbar.png"];
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

但现在我正在使用 eventkit 框架。我想要的是当我去事件详细信息时,我得到标准的导航栏布局。所以没有图像。

EKEventViewController *vc = [[EKEventViewController alloc] init];
[vc.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
vc.event = [dataSource eventAtIndexPath:indexPath];
vc.allowsEditing = YES;
[calendar.navigationController pushViewController:vc animated:YES];

我尝试了以下方法,但它不起作用。 有什么帮助吗?

【问题讨论】:

  • 您是否尝试将 [vc.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault] 命令放入 EKEventViewController 类本身的 viewWillAppear 中?
  • 您无法访问该课程?这是 eventKit 框架内的一个类
  • 怎么不工作了?图像没有变化吗?
  • 不,图像没有改变。

标签: iphone ios objective-c uinavigationcontroller


【解决方案1】:

你可以做一件事,用默认导航栏截取一个 viewController 的截图,只裁剪导航栏区域,即制作 320 x 44 大小的图像。

当你想要再次使用默认导航栏时,使用这个裁剪的图像作为导航栏的背景,添加以下代码

UIImage *image = [UIImage imageNamed:@"defaultNavbar.png"];
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

当您导航到另一个具有自定义 Navimage 的 viewController 时,再次借助您的自定义图像代码绘制导航图像,即

UIImage *image = [UIImage imageNamed:@"navbar.png"];
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    • 1970-01-01
    相关资源
    最近更新 更多