【问题标题】:Change the background color of a UIActivityViewController更改 UIActivityViewController 的背景颜色
【发布时间】:2013-11-07 18:36:29
【问题描述】:

在 iOS 7 中,标准 UIActivityViewController 具有半透明的白色背景。相反,我的应用程序有一个黑暗的主题。当白色的UIAcitivityViewController 出现在黑暗的应用背景上时,看起来很糟糕。

有没有办法改变一个 UIAcitivityViewController的背景颜色?

我试过了 activityVC.view.backgroundColor = [UIColor blackColor],但这会使整个屏幕变黑,而不仅仅是UIAcitivity图标所占据的区域,如标准的白色背景。

【问题讨论】:

    标签: ios ios7 uicolor uiactivityviewcontroller


    【解决方案1】:

    强制 UIActivityViewController 进入暗模式的 Swift 答案(同样适用于亮模式,只需将 .dark 替换为 .light):

    activityViewController.overrideUserInterfaceStyle = .dark
    
    // these two are needed for the modification of the Save to Files dialog
    UINavigationBar.appearance().overrideUserInterfaceStyle = .dark
    UITableView.appearance().overrideUserInterfaceStyle = .dark
    

    【讨论】:

      【解决方案2】:

      我得到的只是改变主视图的背景。尝试更改其中标签的颜色没有成功。

      let aType = NSClassFromString("_UIShareExtensionRemoteViewController") as! UIAppearanceContainer.Type
      UIView.appearance(whenContainedInInstancesOf: [aType.self]).backgroundColor = UIColor.red
      

      【讨论】:

        【解决方案3】:

        虽然我的解决方案似乎有点不稳定,但它适用于 iOS7 和 iOS8。如果某些事情突然发生变化,它也不会让您的应用崩溃;

        UIActivityViewController *aVC = [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL urlWithString:@"http://example.com"] applicationActivities:nil];
        id targetView = [[[[[[[[[[[aVC.view.subviews lastObject] subviews] firstObject] subviews] firstObject] subviews] firstObject] subviews] firstObject] subviews] firstObject];
        if ([targetView respondsToSelector:@selector(setBackgroundColor:)])
        {
            UIColor *targetColor = ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) ? [[UIColor redColor] colorWithAlphaComponent:0.3] : [UIColor redColor];
            [targetView setBackgroundColor:targetColor];
        }
        

        模拟器中的样子,例如:

        【讨论】:

          【解决方案4】:
          socialActivityPopover = [[UIPopoverController alloc] initWithContentViewController:activityView];
          [socialActivityPopover setBackgroundColor:[UIColor redColor]];
          

          【讨论】:

          • 请添加一些解释。
          【解决方案5】:

          这应该可以解决问题:

          [[UIView appearanceWhenContainedIn:[UIActivityViewController class], nil] setBackgroundColor:[UIColor greenColor]];
          

          【讨论】:

          • 这和activityVC.view.backgroundColor = [UIColor blackColor]的效果一样。它使所有东西都变黑,而不仅仅是带有图标的下部。此外,当我选择带有 alpha 的颜色(即 0.5)时,它看起来很奇怪,因为我可以看到子视图的框架。
          猜你喜欢
          • 1970-01-01
          • 2022-01-25
          • 2013-08-08
          • 1970-01-01
          • 1970-01-01
          • 2012-04-21
          相关资源
          最近更新 更多