Ios7 iOS 7中UIActivityViewController的模式状态栏和导航栏文本颜色
当我使用Ios7 iOS 7中UIActivityViewController的模式状态栏和导航栏文本颜色,ios7,uinavigationbar,uiactivityviewcontroller,textcolor,tintcolor,Ios7,Uinavigationbar,Uiactivityviewcontroller,Textcolor,Tintcolor,当我使用UIActivityViewController时,在用户选择活动(如邮件或消息)后,我无法更改状态栏的文本颜色,也无法更改“取消”和“发送”导航栏按钮的文本/色调。对于条形按钮,在AppDelegate中,我尝试使用: [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 什么也没发生。但是,我可以使用以下内容设置导航栏标题: [[UINavigationBar appearance] se
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
中,并且根本没有机会更改状态栏的颜色。有什么想法吗?我认为更改导航栏颜色的代码如下:
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
这是用于更改iOS 7中导航栏按钮的颜色,如果您可能需要:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
如果您想更改iOS 6中按钮的颜色,请使用以下代码:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
此代码也适用于iOS 8+,用于更改UIActivityViewController活动(如通过消息或邮件生成器共享)的条形按钮文本颜色。您必须设置整个应用程序的颜色
self.window.tintColor = [UIColor redColor];
或
条形按钮
self.navigationController.navigationBar.tintColor = [UIColor redColor];
我找到了一个解决方案来更改发送和取消按钮的文本颜色
请核对我的答案
关于将状态栏样式从黑色更改为白色,我几乎尝试了Stackoverflow上的所有功能,但没有任何效果。似乎没有解决办法
有一件事可能会起作用,但我真的不知道如何使用它,那就是更改子视图控制器中的状态栏样式。有一个关于它的帖子
仅当假定MFMailComposer视图控制器
和MFMessageComposeViewController
是UIActivityViewController
的子视图控制器时,这可能有效,因此,如果我们为UIActivityViewController
指定状态栏样式,则子视图控制器应具有与父项相同的状态栏样式
UIViewController
中有一个名为childViewControllerForStatusBarStyle
的方法。这是苹果的文档
但我真的不知道如何使用它。有人知道这一点吗?由于UIActivityViewController显示了底层模型视图控制器,我们使用此解决方案来解决状态栏颜色问题:
@界面状态栏ColorApplyingActivityViewController:UIActivityViewController
@结束
@实现状态BarColorApplyingActivityViewController
-(void)presentViewController:(UIViewController*)viewControllerToPresent动画:(BOOL)标志完成:(void(^)(void))完成{
[超级呈现ViewController:viewControllerToPresent动画:标志完成:^{
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
如果(完成){
完成();
}
}];
}
@结束
如您所见,这只是一个扩展UIActivityViewController的类,它覆盖了presentViewController:animated:completion:
。显示视图控制器后,我们通过完成块中的UIApplication设置状态栏样式。然后我们调用提供给方法的原始完成块(如果有)。而不是从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
}];
在iOS 8中,UIActivityViewController在应用程序的根视图控制器上显示其单独的compose控制器
您需要对根视图控制器(无论是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]];
在状态栏颜色@1pawan中尝试过这个,我也尝试过。它只会更改常规UIViewController的状态栏颜色,对从UIActivityViewControllerI启动的活动的状态栏没有影响我向苹果公司寻求这方面的帮助,他们确认这是一个bug。我已经提交了一份bug报告,所以希望它能在iOS 7.1中得到修复。我建议在bugreport.apple.com上提交一份bug报告,并参考我的,15959753.在iOS 8中,覆盖presentViewController:animated:completion
不起作用,因此我覆盖了viewwillbeen
和viewwilldissequeen
以在样式之间来回更改。状态栏颜色如何表示问题?我按照您在第一部分中的建议做了,但从未调用过。我已经将我的根视图控制器子类化为处理shouldAutorotate
,这很好,但是没有调用presentViewController
。还有其他详细信息吗?它是显示最多的视图控制器的根。我正在为iOS 8+开发一个应用程序,仅供参考,我的应用程序中需要最后一个(UIBarButtonim外观setTintColor)来更改UIActivityViewController活动(如通过消息或邮件生成器共享)的条形按钮文本颜色@MasonG.Zhwiti感谢您的回复。我把它添加到我的答案中。
[[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]];