【问题标题】:How to set the navigation bar color when user taps "More"on UIActivityViewController?当用户在 UIActivityViewController 上点击“更多”时如何设置导航栏颜色?
【发布时间】:2016-01-29 00:40:42
【问题描述】:

每当用户想要选择默认未列出的新共享方法或操作时,通过点击 UIActivityViewController 生成的共享表上的“更多”按钮,将显示一个新视图,如下所示:

如您所见,导航栏是白色的,而它的背景是浅灰色的。如何更改这些颜色以反映我的应用 UI?

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    我这样做了,它对我有用:

    子类UIActivityViewController 并覆盖-(void)presentViewController:animated:completion:

    - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
    [viewControllerToPresent.view setTintColor:[[UINavigationBar appearance] tintColor]];
    for (UIView *view in viewControllerToPresent.view.subviews) {
        if ([view isKindOfClass:[UINavigationBar class]]) {
            UINavigationBar *navigationBar = (UINavigationBar*)view;
            UIImage *navigationBarImage = [[UINavigationBar appearance] backgroundImageForBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
            [navigationBar setBackgroundImage:navigationBarImage forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
            [navigationBar setTitleTextAttributes:[[UINavigationBar appearance] titleTextAttributes]];
        }
    }
    
    [super presentViewController:viewControllerToPresent animated:flag completion:^{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        if (completion) {
            completion();
        }
    }];
    }
    

    【讨论】:

      【解决方案2】:

      在打开之前在模态框上设置此属性,例如:

      modal.navigationController.navigationBar.barTintColor = ...
      

      您能否提供一些代码让我们看看您现在正在尝试什么?

      【讨论】:

        【解决方案3】:

        在导航栏设置tintColorbarTintColor

            self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
            self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
        

        tintColor 用于导航项和栏按钮项 barTintColor如果用于导航栏背景。

        【讨论】:

        • 这会在共享表上更改栏,但是当点击“更多”按钮时,会打开一个具有不同栏颜色的模式。
        【解决方案4】:

        您可能会使用 UIAppearance 选择器来修改应用程序上的所有导航栏,方法是在类上调用它。相反,在单个对象上调用外观方法,这样可以避免系统导航栏被这样着色。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-12-14
          • 1970-01-01
          相关资源
          最近更新 更多