覆盖MFMailComposeViewController的UIAppearance属性

mar*_*son 17 cocoa-touch objective-c ios uiappearance ios6

我正在使用UIAppearance协议在我的应用程序中设置UINavigationBar对象的背景图像.

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"image-name"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

我想为MFMailComposeViewController的实例覆盖它,以便显示默认样式导航栏.我尝试使用appearanceWhenContainedIn来设置它,这适用于iOS 5但不适用于iOS 6.

[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

我是犯了错误还是有更好的方法来实现这个目标?

小智 24

通过正常的措施改变MFMailComposer的外观是不可能的,但是你可以做一些解决方法,我以前曾多次使用过.

将两个方法添加到要在其中实现新外观的类中:

- (void)applyComposerInterfaceAppearance
{
    [[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
}

- (void)applyGlobalInterfaceAppearance
{
    // My default color of choice
    [[UINavigationBar appearance] setTintColor:[UIColor redColor]];
}
Run Code Online (Sandbox Code Playgroud)

现在,在show方法中,应用您想要进行的特殊编辑器界面更改.

- (void)showMailComposer
{
    if ([MFMailComposeViewController canSendMail]) 
    {
        [self applyComposerInterfaceApperance];

        MFMailComposeViewController *viewController = [[MFMailComposeViewController alloc] init];
        viewController.mailComposeDelegate = delegate;
        [viewController setToRecipients:mailRecepients];
        [viewController setSubject:mailSubject];
        [viewController setMessageBody:messageBody isHTML:NO];
        [self presentModalViewController:viewController animated:YES];
    }
}
Run Code Online (Sandbox Code Playgroud)

在您的委托中,将界面更改回原来的样式.

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    // Do normal mail composer did finish stuff in here
    [self applyGlobalInterfaceAppearance];
}
Run Code Online (Sandbox Code Playgroud)

  • @Ziconic,你能不能告诉我你是如何在运行中"取消"你的uiappearance属性?谢谢 (2认同)