cdts/xdts-ios 3/TreeHole/CYHResetCode/CYH/QMUIKit/QMUIComponents/QMUITheme/QMUIThemeManager.h

121 lines
8.8 KiB
C
Raw Permalink Normal View History

2023-07-27 09:20:00 +08:00
/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2021 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// QMUIThemeManager.h
// QMUIKit
//
// Created by MoLice on 2019/J/20.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 当主题发生变化时发出这个通知,会先于 UIViewController/UIView 的 qmui_themeDidChangeByManager:identifier:theme:
extern NSNotificationName const QMUIThemeDidChangeNotification;
/**
identifier UIViewController UIView viewController view qmui_themeDidChangeByManager:identifier:theme: colorimage QMUIThemeManagerCenter light/dark 2 white/yellow/green/black 4使 QMUIThemeManagerCenter.defaultThemeManager QMUIThemeManager 使 +[QMUIThemeManagerCenter themeManagerWithName:] QMUIThemeManager
GitHub Wiki
@link https://github.com/Tencent/QMUI_iOS/wiki/%E4%BD%BF%E7%94%A8-QMUITheme-%E5%AE%9E%E7%8E%B0%E6%8D%A2%E8%82%A4%E5%B9%B6%E9%80%82%E9%85%8D-iOS-13-Dark-Mode
theme
1. identifier /theme NSObject identifier theme
2. QMUIThemeManager addThemeIdentifier:theme:removeThemeIdentifier:/removeTheme:
3. QMUIThemeManager themeIdentifiersthemes
4. QMUIThemeManager currentThemeIdentifiercurrentTheme App
iOS 13 Dark Mode
1. App iOS 13 使 QMUIThemeManager QMUIThemeManager App iOS iOS 13 Dark Mode iOS 13 QMUIThemeManager Dark Mode iOS 12
2. QMUIThemeManager iOS 13 Dark Mode identifierForTrait trait.userInterfaceStyle identifier respondsSystemStyleAutomatically YES
App
1. UIView UIColor/CGColor使 [UIColor qmui_colorWithThemeProvider:] UIColor color CGColor @property使 [UIView qmui_registerThemeColorProperties:] property init NSObject enum/struct [UIView qmui_themeDidChangeByManager:identifier:theme:]
2. UIViewController [UIViewController qmui_themeDidChangeByManager:identifier:theme:]
3. NSObject QMUIThemeDidChangeNotification App
使
1. App theme QMUIThemeManager
2. NSUserDefaults currentThemeIdentifier/currentTheme
3. UIColorCGColor 使 [UIColor qmui_colorWithThemeProvider:] property使 [UIView qmui_registerThemeColorProperties:] property property qmui_themeDidChangeByManager:identifier:theme:
4. QMUIThemeDidChangeNotification 便
5. iOS 13 Dark Mode respondsSystemStyleAutomaticallyidentifierForTrait
*/
@interface QMUIThemeManager : NSObject
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@property(nonatomic, copy, readonly) __kindof NSObject<NSCopying> *name;
/// 自动响应 iOS 13 里的 Dark Mode 切换,默认为 NO。当为 YES 时,能自动监听系统 Dark Mode 的切换,并通过询问 identifierForTrait 来将当前的系统界面样式转换成业务定义的主题,剩下的事情就跟 iOS 12 及以下的系统相同了。
/// @warning 当设置这个属性为 YES 之前,请先为 identifierForTrait 赋值。
@property(nonatomic, assign) BOOL respondsSystemStyleAutomatically API_AVAILABLE(ios(13.0));
/// 当 respondsSystemStyleAutomatically 为 YES 并且系统样式发生变化时,会通过这个 block 将当前的 UITraitCollection.userInterfaceStyle 转换成对应的业务主题 identifier
@property(nonatomic, copy, nullable) __kindof NSObject<NSCopying> *(^identifierForTrait)(UITraitCollection *trait) API_AVAILABLE(ios(13.0));
/// 获取所有主题的 identifier
@property(nonatomic, copy, readonly, nullable) NSArray<__kindof NSObject<NSCopying> *> *themeIdentifiers;
/// 获取所有主题的对象
@property(nonatomic, copy, readonly, nullable) NSArray<__kindof NSObject *> *themes;
/// 获取当前主题的 identifier
@property(nonatomic, copy, nullable) __kindof NSObject<NSCopying> *currentThemeIdentifier;
/// 获取当前主题的对象
@property(nonatomic, strong, nullable) __kindof NSObject *currentTheme;
/// 当切换 currentThemeIdentifier 时如果遇到该 identifier 尚未被注册,则会尝试通过这个 block 来获取对应的主题对象并添加到 QMUIThemeManager 里
@property(nonatomic, copy, nullable) __kindof NSObject * _Nullable (^themeGenerator)(__kindof NSObject<NSCopying> *identifier);
/// 当切换 currentTheme 时如果遇到该 theme 尚未被注册,则会尝试通过这个 block 来获取对应的 identifier 并添加到 QMUIThemeManager 里
@property(nonatomic, copy, nullable) __kindof NSObject<NSCopying> * _Nullable (^themeIdentifierGenerator)(__kindof NSObject *theme);
/**
@param identifier identifier NSString
@param theme class
*/
- (void)addThemeIdentifier:(__kindof NSObject<NSCopying> *)identifier theme:(__kindof NSObject *)theme;
/**
identifier
@param identifier identifier
*/
- (void)removeThemeIdentifier:(__kindof NSObject<NSCopying> *)identifier;
/**
@param theme
*/
- (void)removeTheme:(__kindof NSObject *)theme;
/**
identifier
@param identifier identifier
@return identifier
*/
- (nullable __kindof NSObject *)themeForIdentifier:(__kindof NSObject<NSCopying> *)identifier;
/**
identifier
@param theme
@return identifier
*/
- (nullable __kindof NSObject<NSCopying> *)identifierForTheme:(__kindof NSObject *)theme;
@end
NS_ASSUME_NONNULL_END