【问题标题】:Problem with NavigationBar and UIImagePickerControllerNavigationBar 和 UIImagePickerController 的问题
【发布时间】:2015-07-07 12:29:26
【问题描述】:

在我的应用委托中我有这个:

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

为导航栏设置背景图像。但我需要使用 UIImagePickerController,所以我有这段代码:

 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
    picker.navigationBar.barStyle = UIBarStyleDefault;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
}

结果是:

我想要默认的 UIImagePickerController 导航栏样式。我不想在应用程序中使用图像背景,我想要默认导航栏。

我该如何解决?

非常感谢。

【问题讨论】:

  • 好吧,是吗?我也很想知道。

标签: iphone uiimagepickercontroller uinavigationbar


【解决方案1】:

删除导航栏的代码并删除调用drawRect这个函数的语句。

它删除了自定义导航栏,然后您将获得默认导航栏。

【讨论】:

    【解决方案2】:
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        if ([navigationController isKindOfClass:[UIImagePickerController class]]) {
            if ([[UIDevice currentDevice] systemVersion].floatValue >= 8.0) {
                [viewController.navigationController.navigationBar setBarTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"navbar1"]]];
            } else {
                [viewController.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar2"] forBarMetrics:UIBarMetricsDefault];
            }
        viewController.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont boldSystemFontOfSize:18.0f];
        titleLabel.text = @"photos";
        [viewController.navigationItem setTitleView:titleLabel];
        viewController.edgesForExtendedLayout = UIRectEdgeNone;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      • 2012-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多