覆盖了MFMailComposeViewController UIAppearance财产(Over

2019-07-22 19:39发布

我现在用的是UIAppearance协议设置贯穿我的应用程序UINavigationBar的对象的背景图像。

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"image-name"] forBarMetrics:UIBarMetricsDefault];

我想,这样显示的默认样式的导航栏,以覆盖此为MFMailComposeViewController的实例。 我试图使用appearanceWhenContainedIn设置此,这适用于iOS 5,但不是在iOS 6。

[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

我在犯错误或有更好的方法来做到这一点?

Answer 1:

Changing the appearance of a MFMailComposer through normal measures is not possible, but there is a little workaround you can do, which I've used many times before.

Add two methods to the class in which you wish to implement the new look to:

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

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

Now in your show method, apply the special composer interface changes you'd like to make.

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

And in your delegate, change the interface back to the way it was.

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


Answer 2:

邮件作曲视图是在不同的工艺的iOS 6下运行,并且不能直接被篡改(因为视图基本上是另一个应用程序内)。 您不能自定义其显示的内容,它是Twitter的和Facebook的看法相同。

这里是远程视图控制器的更详细的描述: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/



Answer 3:

只需设置tintColor上MFMailComposeViewController实例:

[mailInstance.navigationBar setTintColor:[UIColor someColor]];


文章来源: Override UIAppearance property for MFMailComposeViewController