IActivityViewControllers的模态状态栏和导

IActivityViewControllers的模态状态栏和导

本文介绍了iOS 7中UIActivityViewControllers的模态状态栏和导航栏文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 UIActivityViewController 时,在用户选择活动(例如邮件或消息)后,我无法更改状态栏的文本颜色,也不能取消和发送导航栏按钮的文本/色调颜色。对于条形按钮,在 AppDelegate 中我尝试使用:

When I'm using a UIActivityViewController, after the user chooses an activity (such as Mail or Message), I can not change the text color for the status bar nor the text/tint color of the Cancel and Send navigation bar buttons. For the bar buttons, in the AppDelegate I've tried using:

    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

没有任何反应。但是我可以用这个设置导航栏标题:

And nothing happens. However I am able to set the navigation bar title with this:

    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil]];

我将 UIViewControllerBasedStatusBarAppearance 设置为 Info.plist 中。并把这行:

I set the UIViewControllerBasedStatusBarAppearance to NO in the Info.plist. And put the line:

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

AppDelegate 中,并且没有运气改变状态栏的颜色。任何想法?

in the AppDelegate, and have had no luck changing the status bar color at all. Any ideas?

推荐答案

当UIActivityViewController呈现底层模型视图控制器时,我们使用此解决方法来修复状态栏颜色问题:

As the UIActivityViewController presents the underlying model view controllers, we use this workaround to fix the status bar color issue:

@interface StatusBarColorApplyingActivityViewController : UIActivityViewController

@end

@implementation StatusBarColorApplyingActivityViewController

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
  [super presentViewController:viewControllerToPresent animated:flag completion:^{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    if (completion) {
      completion();
    }
  }];
}

@end

如你所见,这个只是一个扩展UIActivityViewController的类覆盖 presentViewController:animated:completion:。当呈现视图控制器时,我们通过完成块中的UIApplication设置状态栏样式。然后我们调用给出方法的原始完成块,如果有的话。

As you can see, this is just a class extending the UIActivityViewController overriding the presentViewController:animated:completion:. When the view controller has been presented we set the status bar style via UIApplication in the completion block. Then we call the original completion block given to the method, if any.

这篇关于iOS 7中UIActivityViewControllers的模态状态栏和导航栏文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:17