【问题标题】:Preventing Customization of MFMailComposeViewController Background Image防止自定义 MFMailComposeViewController 背景图像
【发布时间】:2012-07-27 21:40:19
【问题描述】:

目前我们正在使用这段代码在整个应用中自定义 UINavigationBar 背景图像:

@implementation UINavigationBar(MyExtensions)

- (UIImage *)barBackground {
    return [UIImage imageNamed:@"GlobalTitleBackground.png"];
}

- (void)didMoveToSuperview {
    //iOS5 only
    if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
    {
        [self setBackgroundImage:[self barBackground] forBarMetrics:UIBarMetricsDefault];
    }
}

//this doesn't work on iOS5 but is needed for iOS4 and earlier
- (void)drawRect:(CGRect)rect {
    //draw image
    [[self barBackground] drawInRect:rect];
}

@end

总的来说,这很好用。我遇到的问题是,当我创建一个 MFMailComposeViewController 时,它的背景也会被自定义。

因此,鉴于我现在拥有的代码,是否有可能对所有 UINavigationBars除了由 MFMailComposeViewController 创建的 UINavigationBar 进行自定义?

提前致谢!

【问题讨论】:

    标签: objective-c ios cocoa-touch uinavigationbar mfmailcomposeviewcontroller


    【解决方案1】:

    一种解决方案是使用 view.tag 属性过滤掉特定的导航控制器。

    当您创建 MFMailComposeViewController 以向导航栏添加标签时。

    例如:

    //In other VC
    MFMailController *mailVC = [[MFMailController alloc] init];
    mailVC.navigationBar.tag = 5678;
    
    //In @implementation UINavigationBar(MyExtensions)
    - (UIImage *)barBackground {
        if (self.tag != 5678)
            return [UIImage imageNamed:@"GlobalTitleBackground.png"];
        }
        return nil;
    }
    

    【讨论】:

    • 除此之外还有哪些解决方案?
    • 您可以删除该特定视图 MFMailController 的自定义导航栏。 [mailVC setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    猜你喜欢
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    相关资源
    最近更新 更多