Objective C 判断当前 iOS 是否正在使用深色外观

Objective C 2020-03-19 阅读 919 评论 0

iOS 13 推出的“深色”模式为 iPhone 带来了全然不同的新风格。IOS项目,使用 Objective C,判断是否为深色模式(Dark Mode)。由于暗黑模式是在 IOS 13 才出现的,可以结合 @available 属性表达式。@available(iOS 13.0, *) 表示在 iOS 的版本等于或者大于 13.0 的时候可见。

/// 判断当前是否使用暗黑外观
- (BOOL)inDarkAppearance{
  BOOL res = NO;
  if (@available(iOS 13.0, *)) {
    switch (UITraitCollection.currentTraitCollection.userInterfaceStyle) {
      case UIUserInterfaceStyleDark:
        NSLog(@"深色模式");
        res = YES;
        break;
      case UIUserInterfaceStyleLight:
        NSLog(@"浅色模式");
        break;
      case UIUserInterfaceStyleUnspecified:
        NSLog(@"未指定");
        break;
    }
  }
  return res;
}
最后更新 2020-03-21
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });