NavigationBar 和 UIImagePickerController 的问题

发布于 2024-10-07 12:31:30 字数 1050 浏览 0 评论 0原文

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

@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导航栏样式。我不想在应用程序中使用图像背景,我想要默认的导航栏。

我该如何修复它?

非常感谢。

in my app delegate I've this:

@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

for set a background image for navigationbar. But I need to use a UIImagePickerController, so I've this code:

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

The result is:

alt text

I want the default UIImagePickerController navigationbar style. I don't want the image background used in application, I want the default navigationbar.

How can I fix it?

Very thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔少女心 2024-10-14 12:31:30

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

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

remove code for navigation bar and remove the statement where you call drawRect this function.

it remove the custom navigation bar and then you get default navigation bar.

梦里的微风 2024-10-14 12:31:30
- (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;
    }
}
- (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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文