标签: ios-darkmode

iPhone模拟器中是否有在暗模式和亮模式之间切换的键盘快捷键?

我使用 iPhone 模拟器进行开发,大部分 ui 组件都是使用 swift 编写的。有没有一种简单的方法可以在暗模式和亮模式之间切换以进行测试?

我发现从设置中启用和禁用暗模式非常耗时。这个快捷方式将加快我对暗模式和亮模式的可测试性。

iphone keyboard-shortcuts ios-simulator ios-darkmode

6
推荐指数
3
解决办法
2490
查看次数

更改 ASAuthorizationAppleIDButton 样式 深色/浅色模式已打开

我有一个登录苹果按钮。.black它在灯光模式下有风格:

let button = ASAuthorizationAppleIDButton(type: .signIn, style: .black)
Run Code Online (Sandbox Code Playgroud)

.white我希望它在深色模式下有风格

访问样式来更改它似乎不可能像这样:

button.style = .white
Run Code Online (Sandbox Code Playgroud)

有人知道这是否可以以干净的方式实现吗?无需重新创建按钮

traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
Run Code Online (Sandbox Code Playgroud)

检测到模式改变?

ios swift ios13 ios-darkmode

6
推荐指数
1
解决办法
1020
查看次数

我们如何在 iOS 13 的当前 iOS 应用中支持暗模式?

我当前的应用程序是用 objC 和 Swift 开发的。我需要支持暗模式。谁能建议我如何在全球范围内实现这一目标?

iphone ios ios13 ios-darkmode

5
推荐指数
2
解决办法
4487
查看次数

如何通过darkMode iOS 13禁用更改statusBar textColor

我将whilebackgroundColor NavigationBardarktextColor用于statusBar,但是当用户将主题iOS更改为深色时,我的textColor statusBar更改为while,而while我的backgroundColor上NavigationBar则看不到任何东西。如何为我的应用禁用此更改?

uistatusbar ios13 ios-darkmode

5
推荐指数
3
解决办法
3512
查看次数

UIColor 动态提供程序块有时会收到错误的 userInterfaceStyle

我正在更新一堆颜色以支持新的 iOS 13 暗模式。我通过新的动态提供程序块构造函数以编程方式使用它们。这里的问题是,有时会使用错误的userInterfaceStyle属性值调用块,导致颜色返回错误的值(有时是暗而不是亮,有时是亮而不是暗)。

根据我的理解,我不需要traitCollection使用这个新的构造函数来监听更改或任何类型的事情。它应该自动执行(还是我错了?)。

有趣的是,我尝试通过资产目录使用一些虚拟颜色来完成它,但它也不起作用。还尝试使用一些新系统提供的动态颜色,如 .systemBackgroundColor。有时它还可以解决颜色错误。

if #available(iOS 13.0, *) {
    return UIColor { (traitCollection: UITraitCollection) -> UIColor in
        if traitCollection.userInterfaceStyle == .dark {
            return darkColor
        }
        else {
            return lightColor
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

那么,究竟应该发生什么?这应该像我期望的那样工作还是我绝对需要在特定位置(如 insideviewWillLayoutSubviewstraitCollectionDidChange)分配颜色?

使用.resolvedColor(with: UITraitCollection)作品手动解析颜色。但是根据我从文档中的理解,我不需要像这样手动解决它。

ios swift ios13 ios-darkmode

5
推荐指数
1
解决办法
1350
查看次数

为什么iOS13更改段落<p>的NSAttributedString内的字体系列

我的应用程序使用NSAttributedString向用户显示文本。这些文字大部分位于HTML标记(<p>)段落内。当它位于标签内时,字体系列将更改为某些Times样式。
在我们没有遇到此问题之前,它发生在新版本的iOS 13中。

在此图像上,您可以看到常规字体和修改后的字体。

标签:https : //imgur.com/a/YY3Gdph

我们不知道从哪里开始寻找解决方案。

let font = UIFont.preferredFont(forTextStyle: .body)
let strDesc: String = "\(explanation)\n"
let newStringDesc = strDesc.replacingOccurrences(of: "</ul>", with: "</ul><br>")

let modifiedString = "<style>body{font-family: '\(font.fontName)'; font-size:\(font.pointSize)px;}</style>\(strDesc)"
guard let data = modifiedString.data(using: .utf8) else { return nil }

let attrString = try NSMutableAttributedString(
    data: data,
    options: [
              NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html,

NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue,
                ],
    documentAttributes: nil
)
attrString.addCustomParagraphSettings(font: font)
attrString.setCustomParagraphFontColor()

let mainAttributedText = NSMutableAttributedString()

mainAttributedText.append(attrString)
mainAttributedText.append(tmpTakenText)
descriptionTextView.attributedText = mainAttributedText
Run Code Online (Sandbox Code Playgroud)

我希望看到标准的iOS字体。

swift ios13 ios-darkmode

5
推荐指数
1
解决办法
624
查看次数

iOS13:如何在资产目录中为提升的用户界面级别指定颜色

iOS 13 为我们带来了UIUserInterfaceLevel,可以是.base.elevatedUIView当在黑暗模式下使用升高的级别时,系统似乎会自动调整提供的颜色。

但是,似乎没有办法在资产目录中手动指定.elevated颜色,是吗?

唯一的方法似乎是通过新的 UIColor 构造函数

UIColor.init { (traits) -> UIColor in
   traits.userInterfaceLevel == .elevated ? UIColor(named: "myColor-elevated")! : UIColor(named: "myColor")!
}
Run Code Online (Sandbox Code Playgroud)

uicolor uitraitcollection ios13 ios-darkmode

5
推荐指数
1
解决办法
585
查看次数

在故事板中使用材质样式时,iOS 13.0 警告之前的系统模糊样式

我正在尝试使我的应用程序适应 iOS 13 暗模式,当我将 UIVisualEffectView 的模糊设置为 Storyboard 中的任何新模式(如材质)时,我收到警告:

System blur style before iOS 13.0
Run Code Online (Sandbox Code Playgroud)

我理解这一点,并且我可以在代码中使用版本检查来支持 iOS 13 和以前的版本。但是,我不确定如何在 Storyboard(我更喜欢)中执行此操作,并且当我在 iOS 12 设备中运行该应用程序时,它实际上呈现良好(正确回退)。

我怎样才能摆脱警告?

谢谢!

storyboard ios uivisualeffectview ios-darkmode

5
推荐指数
1
解决办法
2561
查看次数

如何在flutter中使用暗模式和不同分辨率的资源图像?

我在我的 flutter 项目中使用具有不同分辨率的图像,如此处所述。现在我想为深色模式主题添加自定义图像。我在 pubspec.yaml 中的资产声明如下所示:

flutter:
  uses-material-design: true
  assets:
    - assets/images/img_menu.png
    - ...
Run Code Online (Sandbox Code Playgroud)

我的资产结构:

  .../pubspec.yaml
  .../assets/images/img_menu.png
  .../assets/images/0.75x/img_menu.png
  .../assets/images/1.5x/img_menu.png
  .../assets/images/2.0x/img_menu.png
  .../assets/images/3.0x/img_menu.png
  .../assets/images/4.0x/img_menu.png
Run Code Online (Sandbox Code Playgroud)

我以这种方式在项目中加载图像:

Image.asset('assets/images/img_menu.png')
Run Code Online (Sandbox Code Playgroud)

我知道对于简单的单色图像我可以像这样改变它的颜色:

Image.asset('assets/images/img_menu.png', 
                      color: Theme.of(context).brightness == Brightness.light
                      ? Colors.black
                      : Colors.white,)
Run Code Online (Sandbox Code Playgroud)

但我的大多数图像都比较复杂,所以我必须为它们加载自定义资源。

正如此处所述,在添加暗模式资产后,我可以不做任何更改地保留 pubspec。我尝试过黑暗模式的不同资产结构,但没有一个有效。

1:

  .../pubspec.yaml
  .../assets/images/img_menu.png
  .../assets/images/dark/img_menu.png
  .../assets/images/0.75x/img_menu.png
  .../assets/images/0.75x/dark/img_menu.png
  .../assets/images/1.5x/img_menu.png
  .../assets/images/1.5x/dark/img_menu.png
  .../assets/images/2.0x/img_menu.png
  .../assets/images/2.0x/dark/img_menu.png
  .../assets/images/3.0x/img_menu.png
  .../assets/images/3.0x/dark/img_menu.png
  .../assets/images/4.0x/img_menu.png
  .../assets/images/4.0x/dark/img_menu.png
Run Code Online (Sandbox Code Playgroud)

2:

  .../pubspec.yaml
  .../assets/images/img_menu.png
  .../assets/images/0.75x/img_menu.png
  .../assets/images/1.5x/img_menu.png
  .../assets/images/2.0x/img_menu.png
  .../assets/images/3.0x/img_menu.png
  .../assets/images/4.0x/img_menu.png
  .../assets/images/dark/img_menu.png
  .../assets/images/dark/0.75x/img_menu.png
  .../assets/images/dark/1.5x/img_menu.png
  .../assets/images/dark/2.0x/img_menu.png
  .../assets/images/dark/3.0x/img_menu.png
  .../assets/images/dark/4.0x/img_menu.png
Run Code Online (Sandbox Code Playgroud)

3:

  .../pubspec.yaml
  .../assets/images/img_menu.png
  .../assets/images/0.75x/img_menu.png
  .../assets/images/1.5x/img_menu.png
  .../assets/images/2.0x/img_menu.png
  .../assets/images/3.0x/img_menu.png
  .../assets/images/4.0x/img_menu.png
  .../assets/dark/images/img_menu.png
  .../assets/dark/images/0.75x/img_menu.png
  .../assets/dark/images/1.5x/img_menu.png
  .../assets/dark/images/2.0x/img_menu.png …
Run Code Online (Sandbox Code Playgroud)

assets image flutter ios-darkmode android-dark-theme

5
推荐指数
1
解决办法
2257
查看次数

UIViewController userInterfaceStyle 总是很轻

当启用暗模式时,UIViewControllers 总是使用亮模式。viewController.traitCollection.userInterfaceStyle 总是 Light 但 window.traitCollection.userInterfaceStyle 是 Dark。

UIUserInterfaceStyle 未在 plist 中设置。我尝试了所有可能的设置 - 将 UIUserInterfaceStyle 添加到 plist,为 UIWindow 和 UIViewController 设置 overrideUserInterfaceStyle。我为不同的情况记录了 userInterfaceStyle,结果是

TestDarkModeViewController *testController = [[TestDarkModeViewController alloc] initWithNibName:@"TestDarkModeViewController" bundle: nil];
testController.traitCollection.userInterfaceStyle //result Light
Run Code Online (Sandbox Code Playgroud)

但对于

UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:testController];
navController.traitCollection.userInterfaceStyle //result Dark

UIViewController *testController2 = [[UIViewController alloc]init];
testController2.traitCollection.userInterfaceStyle //result Dark
Run Code Online (Sandbox Code Playgroud)

似乎只有当控制器以编程方式从 xib 文件加载时才会发生。知道什么是错误的以及如何解决这个问题吗?

ios ios-darkmode

5
推荐指数
1
解决办法
132
查看次数