当我使用UIActivityViewController
时,在用户选择活动(例如邮件或消息)后,我无法更改状态栏的文本颜色,也无法更改取消的文本/色调颜色发送导航栏按钮。对于条形按钮,我尝试使用AppDelegate
:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
没有任何反应。但是我可以用这个设置导航栏标题:
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil]];
我在UIViewControllerBasedStatusBarAppearance
中将NO
设置为Info.plist
。并把这条线:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
<{1>}中的,根本没有改变状态栏颜色的运气。有什么想法吗?
答案 0 :(得分:7)
当UIActivityViewController呈现底层模型视图控制器时,我们使用此解决方法来修复状态栏颜色问题:
@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设置状态栏样式。然后我们调用给该方法的原始完成块,如果有的话。
答案 1 :(得分:4)
我们可以在显示导航栏时更改tintColor,并在UIActivityViewController
完成后将其还原,而不是从completionHandler
进行子类化。例如:
UIColor *normalColor = [[UINavigationBar appearance] tintColor];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
// back to normal color
[[UINavigationBar appearance] setTintColor:normalColor];
}];
[self presentViewController:activityViewController animated:YES completion:^{
// change color to suit your need
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:25.0f/255.0f green:125.0f/255.0f blue:255.0f/255.0f alpha:1.0f]]; // ActionSheet options' Blue color
}];
答案 2 :(得分:2)
我相信更改导航栏颜色的代码是:
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
如果您需要,可以更改iOS 7中导航栏按钮的颜色:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
如果你想改变iOS 6中按钮的颜色,这就是代码:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
此代码也适用于iOS 8+以更改UIActivityViewController活动的条形按钮文本颜色(例如通过消息或邮件编辑器共享)。
答案 3 :(得分:2)
在iOS 8中,UIActivityViewController在应用程序的根视图控制器上显示其各自的组合控制器。
您需要继承您的根视图控制器(无论是UIViewController还是UINavigationController)并添加以下代码。
@interface UINavigationControllerBarColor : UINavigationController
@end
@implementation UINavigationControllerBarColor
- (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
然后不是在AppDelegate或storyboard中初始化UINavigationController,而是初始化新的子类控制器。
其他一些建议是UIActivityViewController的子类,但这不起作用。
如果您想更改条形按钮和标题颜色,请在您的应用程序中使用以下内容:didFinishLaunching:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont systemFontOfSize:18.0f], UITextAttributeFont,
nil]];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]];
答案 4 :(得分:0)
我找到了一个解决方案,可以更改发送和取消按钮的文字颜色。
从here检查我的回答。
关于将状态栏样式从黑色更改为白色,我已经尝试了Stackoverflow上的所有内容,但没有任何效果。似乎没有解决方法。
可能有用的一件事,但我真的不知道如何使用它,可能会改变子视图控制器中的状态栏样式。有关于它的Stackoverflow帖子here。
这可能仅在假设MFMailComposerViewController
和MFMessageComposeViewController
是UIActivityViewController
的子视图控制器并因此我们为UIActivityViewController
指定状态栏样式时才有效子视图控制器应具有与父视图相同的状态栏样式。
UIViewController
中有一个名为childViewControllerForStatusBarStyle
的方法。 Here是Apple的文档。
但我真的不知道如何使用它。有没有人想到这个?
答案 5 :(得分:-1)
您必须设置整个应用的tintColor。
self.window.tintColor = [UIColor redColor];
或
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
栏按钮
self.navigationController.navigationBar.tintColor = [UIColor redColor];