NavigationBar和UIImagePickerController的问题

时间:2010-12-16 03:08:12

标签: iphone uiimagepickercontroller uinavigationbar

在我的app委托中我就是这样:

@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];
    }
}

结果是:

alt text

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

我该如何解决?

非常感谢。

2 个答案:

答案 0 :(得分:0)

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

删除自定义导航栏,然后获取默认导航栏。

答案 1 :(得分:0)

- (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;
    }
}