改变Modal UIActivityViewController的外观

时间:2012-12-18 11:14:34

标签: objective-c ios modalviewcontroller uiappearance uiactivityviewcontroller

如何更改模态共享操作中使用的UIActivityViewController邮件撰写对象的导航栏的外观?

UINavigationBar - Wrong Tint

UIActivityViewController符合UIAppearance,因此我认为以下内容确实有效,但事实并非如此。导航栏保持默认蓝色。

activityVC.navigationController.navigationBar.tintColor = [UIColor greyColor];

上下文:

    - (IBAction)share {
        NSString *textToShare = ...;
        NSURL *url = ...;

        NSArray *activityItems = [[NSArray alloc]  initWithObjects:textToShare,url,nil];

        UIActivity *activity = [[UIActivity alloc] init];
        NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
        UIActivityViewController *activityVC =
        [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
        [activityVC setExcludedActivityTypes:[NSArray arrayWithObjects:                                              UIActivityTypeMessage,UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,UIActivityTypePostToWeibo,                                              UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,
                                              nil]];

        activityVC.navigationController.navigationBar.tintColor = [UIColor greyColor];

        [self presentViewController:activityVC animated:YES completion:nil];
    }

如何将UINavigationBar的色调从蓝色更改为灰色。

1 个答案:

答案 0 :(得分:5)

在您的应用程序代理中执行此操作,它将在显示导航栏的整个应用程序中更改导航栏的颜色

[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:.9 green:.9 blue:.9 alpha:1]];

您还可以在“应用程序代理”中使用此更改文本颜色和字体

NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                           [UIColor redColor],UITextAttributeTextColor,
                                           [UIFont fontWithName:@"Arial" size:19],UITextAttributeFont,
                                           nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];