使用UIActivityViewController时,在用户选择活动(如邮件或消息)后,我不能更改状态栏的文本颜色,也不能更改取消和发送导航栏按钮的文本/色调颜色。对于栏按钮,在我尝试使用的AppDelegate中:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];什么都不会发生。但是,我可以使用以下命令设置导航栏标题:
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil]];我在Info.plist中将UIViewControllerBasedStatusBarAppearance设置为NO。并放入这行代码:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];在AppDelegate中,并且根本没有机会更改状态栏的颜色。有什么想法吗?
发布于 2014-07-23 19:19:26
当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正如您所看到的,这只是一个类,它扩展了覆盖presentViewController:animated:completion:的UIActivityViewController。当视图控制器出现时,我们在完成块中通过UIApplication设置状态栏样式。然后,我们调用提供给该方法的原始完成块(如果有)。
发布于 2014-09-02 20:36:28
我们可以在呈现导航栏时更改导航栏的tintColor,并在completionHandler中完成时恢复它,而不是从UIActivityViewController派生子类。例如:
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
}];发布于 2013-11-21 20:12:28
我相信改变导航栏颜色的代码是这样的:
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];这是为了在iOS 7中更改导航栏按钮的颜色,如果您需要的话:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];如果你想在iOS 6中改变按钮的颜色,代码如下:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];此代码还用于iOS 8+更改UIActivityViewController活动(如通过消息或邮件编辑器共享)的条形按钮文本颜色。
https://stackoverflow.com/questions/19794317
复制相似问题