【问题标题】:Change color of UIDocumentInteractionController nav bar更改 UIDocumentInteractionController 导航栏的颜色
【发布时间】:2011-10-14 20:42:29
【问题描述】:

有没有办法改变UIDocumentInteractionController navigationbar 的色调/背景颜色?

【问题讨论】:

    标签: objective-c xcode ios4 uidocumentinteraction


    【解决方案1】:

    @DOOManics 实现的更简洁版本:

    - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
    {
        return [self navigationController];
    }
    

    【讨论】:

      【解决方案2】:

      如果您将 UIDocumentInteractionController 放到 UINavigationController 上,它会自动为其导航栏设置颜色。这可能是您的根视图导航控制器。

      您可以使用documentInteractionControllerViewControllerForPreview 方法执行此操作:

      - (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
      {
          // Use the rootViewController here so that the preview is pushed onto the navbar stack
          MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
          return appDelegate.window.rootViewController;
      }
      

      【讨论】:

        【解决方案3】:

        [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:107.0/256.0 green:145.0/256.0 blue:35.0/256.0 alpha:1.0]];

        将此代码放在 Appdelegate 的 didFinisLaunching 方法中。它将改变整个应用导航栏的颜色。

        【讨论】:

        • 这会改变整个应用的颜色
        【解决方案4】:

        试试这个代码:

        - (void)openEC:(NSURL*)url {  
             [UINavigationBar appearance].tintColor = [UIColor blueColor];  
             docController = [UIDocumentInteractionController interactionControllerWithURL:url];  
            [docController setDelegate:self];  
            [docController  presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];  
        }
        
        - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller {  
            [UINavigationBar appearance].tintColor = [UIColor whiteColor];  
        }
        

        【讨论】:

          【解决方案5】:

          @dvdfrddsgn 实现的 Swift 版本

          试试这个:(你需要实现 UIDocumentInteractionControllerDelegate)

          func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
              return self.navigationController ?? self
          } 
          

          【讨论】:

            【解决方案6】:

            如果您不使用导航控制器,您可以通过在启动 UIDocumentInteractionController 的 UIViewController 的视图上设置正确的设置来设置 UIDocumentInteractionController 中的导航栏颜色。

            假设您有 UIViewController viewController1(从这里启动 UIDocumentInteractionController),在情节提要中有一个 View1。

            在 Storyboard 打开的情况下,从 viewController1 的元素列表中单击 View1,然后转到右侧的“属性检查器”。之后的背景和色调设置也将在您的 UIDocumentInteractionController 中使用。

            然后你可以使用:

            - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
            {
                return self;
            }
            

            请注意,在 viewController1 内部,您可能有一个具有不同属性的导航栏,这些不会在 UIDocumentInteractionController 中使用。

            【讨论】:

            • 在 ios7 上似乎对我不起作用。我按照您的描述更改了色调和背景颜色,但预览视图控制器的按钮保持蓝色。
            猜你喜欢
            • 2018-02-06
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-01-01
            • 2017-02-17
            • 2016-06-03
            相关资源
            最近更新 更多