覆盖MFMailComposeViewController的UIAppearance属性 [英] Override UIAppearance property for MFMailComposeViewController

查看:342
本文介绍了覆盖MFMailComposeViewController的UIAppearance属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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]; 

我有错误或有更好的方法来完成吗?

解决方案

通过正常措施更改MFMailComposer的外观是不可能的,但有一些解决方法你可以做,我已经使用了很多次。



向您希望实现新外观的类添加两个方法:

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

- (void)applyGlobalInterfaceAppearance
{
//我选择的默认颜色
[[UINavigationBar外观] setTintColor:[UIColor redColor] ;
}

现在,在show方法中,应用特殊的composer界面

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

在您的代理中,将接口更改为(MFMailComposeViewController *)控制器didFinishWithResult:(MFMailComposeResult)结果错误:(NSError *)。 )错误
{
//做正常的邮件编辑器在这里完成的东西
[self applyGlobalInterfaceAppearance];
}


I am using the UIAppearance protocol to set the background image of UINavigationBar objects throughout my app.

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

I would like to override this for instances of MFMailComposeViewController so that the default style navigation bar is displayed. I attempted to use appearanceWhenContainedIn to set this and this works on iOS 5 but not on iOS 6.

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

Am I making an error or is there a better way to accomplish this?

解决方案

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)applyComposerInterfaceApperance
{
    [[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];
}

这篇关于覆盖MFMailComposeViewController的UIAppearance属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆