Qt for ios 暗黑模式

环境:Qt5.14.2,MAC10.15.0,IOS13系统,Xcode11 

#include  

class BackgroundColor : public QObject
{
    Q_OBJECT
public:
    explicit BackgroundColor(QObject *parent = nullptr);

public slots:
    int getBackgroundColor();

private:

};

 

#include "backgroundcolor.h"
#include 

BackgroundColor::BackgroundColor(QObject *parent) : QObject(parent)
{

}

enum BackgroundMode{UndefinedColor=0,DarkColor,LightColor};
int  BackgroundColor::getBackgroundColor()
{
    int backgrouondColor=LightColor;
    if (@available(iOS 13.0, *))
    {

        UIColor *lightGrayColor = [UIColor lightGrayColor];
        UIColor *blackColor = [UIColor blackColor];
        UIColor *dyColor= [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                UIColor *color = [UIColor lightGrayColor];
                if (traitCollection.userInterfaceStyle ==UIUserInterfaceStyleDark ) {
                    color =[UIColor blackColor];//dark
                }else if(traitCollection.userInterfaceStyle ==UIUserInterfaceStyleLight){
                     color =[UIColor lightGrayColor];//light
                }
                return color;
            }];

          if(CGColorEqualToColor(dyColor.CGColor, lightGrayColor.CGColor ))
          {
              backgrouondColor=LightColor;
          }
          else   if(CGColorEqualToColor(blackColor.CGColor, blackColor.CGColor ))
          {
              backgrouondColor=DarkColor;
          }
    }

    return  backgrouondColor;
}

下载地址:download.csdn.net/download/alongsxmx/12573377

你可能感兴趣的:(QT,QML)