diff --git a/LEETheme.podspec b/LEETheme.podspec index 24f8f6e..c28672a 100644 --- a/LEETheme.podspec +++ b/LEETheme.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "LEETheme" -s.version = "1.2.1" +s.version = "1.2.2" s.summary = "最好用的轻量级主题管理库" s.homepage = "https://github.com/lixiang1994/LEETheme" diff --git a/LEETheme/LEETheme.h b/LEETheme/LEETheme.h index e4fb150..cc7a6ab 100644 --- a/LEETheme/LEETheme.h +++ b/LEETheme/LEETheme.h @@ -12,7 +12,7 @@ * * @author LEE * @copyright Copyright © 2016 - 2024年 lee. All rights reserved. - * @version V1.2.1 + * @version V1.2.2 */ #import @@ -21,6 +21,8 @@ #import "LEEThemeHelper.h" +#import "LEEThemeImageCache.h" + /* ********************************************************************************* @@ -70,6 +72,10 @@ NS_ASSUME_NONNULL_BEGIN */ + (NSArray *)allThemeTag; +/// 图片缓存 ++ (LEEThemeImageCache *)imageCache; ++ (void)setImageCache:(LEEThemeImageCache *)imageCache; + @end @interface LEETheme (JsonModeExtend) diff --git a/LEETheme/LEETheme.m b/LEETheme/LEETheme.m index bcc3d45..a20ff52 100644 --- a/LEETheme/LEETheme.m +++ b/LEETheme/LEETheme.m @@ -12,7 +12,7 @@ * * @author LEE * @copyright Copyright © 2016 - 2024年 lee. All rights reserved. - * @version V1.2.1 + * @version V1.2.2 */ #import "LEETheme.h" @@ -37,6 +37,8 @@ @interface LEETheme () @property (nonatomic , strong ) NSMutableDictionary *configInfo; +@property (nonatomic , strong ) LEEThemeImageCache *imageCache; + @end @implementation LEETheme @@ -51,12 +53,21 @@ + (LEETheme *)shareTheme{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - themeManager = [[LEETheme alloc]init]; + themeManager = [[LEETheme alloc] init]; }); return themeManager; } +- (instancetype)init +{ + self = [super init]; + if (self) { + _imageCache = [[LEEThemeImageCache alloc] init]; + } + return self; +} + #pragma mark Public + (void)startTheme:(NSString *)tag{ @@ -89,6 +100,16 @@ + (NSArray *)allThemeTag{ return [[LEETheme shareTheme].allTags copy]; } ++ (LEEThemeImageCache *)imageCache { + + return [LEETheme shareTheme].imageCache; +} + ++ (void)setImageCache:(LEEThemeImageCache *)imageCache { + + [LEETheme shareTheme].imageCache = [imageCache copy]; +} + #pragma mark Private - (void)setCurrentTag:(NSString *)currentTag{ @@ -229,19 +250,23 @@ + (id)getValueWithTag:(NSString *)tag Identifier:(NSString *)identifier{ if (imageName) { + UIImage *image = [[LEETheme shareTheme].imageCache getImageWithKey:imageName]; + NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject; NSString *path = configInfo[@"path"]; if (path) path = [documentsPath stringByAppendingPathComponent:path]; - UIImage *image = path ? [UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:imageName]] : [UIImage imageNamed:imageName]; + if (!image) image = path ? [UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:imageName]] : [UIImage imageNamed:imageName]; if (!image) image = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:imageName]]; if (!image) image = [UIImage imageNamed:imageName]; if (image && !value) value = image; + + [[LEETheme shareTheme].imageCache setImage:image withKey:imageName]; } NSDictionary *otherInfo = info[@"other"]; diff --git a/LEETheme/LEEThemeHelper.h b/LEETheme/LEEThemeHelper.h index bd03115..1d7debc 100644 --- a/LEETheme/LEEThemeHelper.h +++ b/LEETheme/LEEThemeHelper.h @@ -12,7 +12,7 @@ * * @author LEE * @copyright Copyright © 2016 - 2024年 lee. All rights reserved. - * @version V1.2.1 + * @version V1.2.2 */ FOUNDATION_EXPORT double LEEThemeVersionNumber; diff --git a/LEETheme/LEEThemeImageCache.h b/LEETheme/LEEThemeImageCache.h new file mode 100644 index 0000000..b033b0b --- /dev/null +++ b/LEETheme/LEEThemeImageCache.h @@ -0,0 +1,32 @@ +/* + * @header LEEThemeImageCache.h + * + * ┌─┐ ┌───────┐ ┌───────┐ + * │ │ │ ┌─────┘ │ ┌─────┘ + * │ │ │ └─────┐ │ └─────┐ + * │ │ │ ┌─────┘ │ ┌─────┘ + * │ └─────┐│ └─────┐ │ └─────┐ + * └───────┘└───────┘ └───────┘ + * + * @brief LEE主题管理 + * + * @author LEE + * @copyright Copyright © 2016 - 2024年 lee. All rights reserved. + * @version V1.2.2 + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface LEEThemeImageCache : NSObject + +- (UIImage *)getImageWithKey:(NSString *)key; + +- (void)setImage:(UIImage *)image withKey:(NSString *)key; + +- (void)clean; + +@end + +NS_ASSUME_NONNULL_END diff --git a/LEETheme/LEEThemeImageCache.m b/LEETheme/LEEThemeImageCache.m new file mode 100644 index 0000000..cf3e846 --- /dev/null +++ b/LEETheme/LEEThemeImageCache.m @@ -0,0 +1,49 @@ +/* + * @header LEEThemeImageCache.m + * + * ┌─┐ ┌───────┐ ┌───────┐ + * │ │ │ ┌─────┘ │ ┌─────┘ + * │ │ │ └─────┐ │ └─────┐ + * │ │ │ ┌─────┘ │ ┌─────┘ + * │ └─────┐│ └─────┐ │ └─────┐ + * └───────┘└───────┘ └───────┘ + * + * @brief LEE主题管理 + * + * @author LEE + * @copyright Copyright © 2016 - 2024年 lee. All rights reserved. + * @version V1.2.2 + */ + +#import "LEEThemeImageCache.h" + +@interface LEEThemeImageCache () + +@property (nonatomic , strong ) NSMutableDictionary *cache; + +@end + +@implementation LEEThemeImageCache + +- (instancetype)init +{ + self = [super init]; + if (self) { + _cache = [NSMutableDictionary dictionary]; + } + return self; +} + +- (UIImage *)getImageWithKey:(NSString *)key { + return self.cache[key]; +} + +- (void)setImage:(UIImage *)image withKey:(NSString *)key { + self.cache[key] = image; +} + +- (void)clean { + [self.cache removeAllObjects]; +} + +@end diff --git a/LEEThemeDemo/LEEThemeDemo.xcodeproj/project.pbxproj b/LEEThemeDemo/LEEThemeDemo.xcodeproj/project.pbxproj index ba6801f..f8456f0 100644 --- a/LEEThemeDemo/LEEThemeDemo.xcodeproj/project.pbxproj +++ b/LEEThemeDemo/LEEThemeDemo.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 9B1415261EE02EF600173BB9 /* image_gray@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B1415251EE02EF600173BB9 /* image_gray@2x.png */; }; 9B1415281EE02F0C00173BB9 /* true_gray@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B1415271EE02F0C00173BB9 /* true_gray@3x.png */; }; 9B14152A1EE02F1A00173BB9 /* true_gray@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B1415291EE02F1A00173BB9 /* true_gray@2x.png */; }; + 9B5711B12C8B208500093AE9 /* LEEThemeImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B5711B02C8B208500093AE9 /* LEEThemeImageCache.m */; }; 9B7873E51E7A3F4A00D4151A /* UITableView+SDAutoTableViewCellHeight.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B7873301E7A3F4A00D4151A /* UITableView+SDAutoTableViewCellHeight.m */; }; 9B7873E61E7A3F4A00D4151A /* UIView+SDAutoLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B7873321E7A3F4A00D4151A /* UIView+SDAutoLayout.m */; }; 9B7875071E7A5AF800D4151A /* UINavigationController+FDFullscreenPopGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B7875061E7A5AF800D4151A /* UINavigationController+FDFullscreenPopGesture.m */; }; @@ -445,6 +446,8 @@ 9B1415251EE02EF600173BB9 /* image_gray@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "image_gray@2x.png"; sourceTree = ""; }; 9B1415271EE02F0C00173BB9 /* true_gray@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "true_gray@3x.png"; sourceTree = ""; }; 9B1415291EE02F1A00173BB9 /* true_gray@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "true_gray@2x.png"; sourceTree = ""; }; + 9B5711AF2C8B208500093AE9 /* LEEThemeImageCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LEEThemeImageCache.h; sourceTree = ""; }; + 9B5711B02C8B208500093AE9 /* LEEThemeImageCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LEEThemeImageCache.m; sourceTree = ""; }; 9B78732E1E7A3F4A00D4151A /* SDAutoLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDAutoLayout.h; sourceTree = ""; }; 9B78732F1E7A3F4A00D4151A /* UITableView+SDAutoTableViewCellHeight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+SDAutoTableViewCellHeight.h"; sourceTree = ""; }; 9B7873301E7A3F4A00D4151A /* UITableView+SDAutoTableViewCellHeight.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+SDAutoTableViewCellHeight.m"; sourceTree = ""; }; @@ -2444,6 +2447,8 @@ 9B9712C71EC42C1C00C1CB79 /* LEETheme.h */, 9B9712C81EC42C1C00C1CB79 /* LEETheme.m */, 9B1081321F42CBA400D3A7E2 /* LEEThemeHelper.h */, + 9B5711AF2C8B208500093AE9 /* LEEThemeImageCache.h */, + 9B5711B02C8B208500093AE9 /* LEEThemeImageCache.m */, ); name = LEETheme; path = ../../LEETheme; @@ -2969,6 +2974,7 @@ 9B78781C1E7B8BCF00D4151A /* CommunityPostCellPhotosView.m in Sources */, 9B7879711E7B92DE00D4151A /* YYRootViewController.m in Sources */, 9B7876631E7A739200D4151A /* YYImageCache.m in Sources */, + 9B5711B12C8B208500093AE9 /* LEEThemeImageCache.m in Sources */, 9B78763A1E7A739200D4151A /* NSBundle+YYAdd.m in Sources */, 9B7878211E7B8BCF00D4151A /* CommunityCircleDetailsViewController.m in Sources */, 9B7876441E7A739200D4151A /* NSString+YYAdd.m in Sources */, @@ -3197,7 +3203,7 @@ ); GCC_PREFIX_HEADER = "$(SRCROOT)/LEEThemeDemo/PrefixHeader.pch"; INFOPLIST_FILE = LEEThemeDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -3226,7 +3232,7 @@ ); GCC_PREFIX_HEADER = "$(SRCROOT)/LEEThemeDemo/PrefixHeader.pch"; INFOPLIST_FILE = LEEThemeDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/LEEThemeDemo/LEEThemeDemo/Librarys/YYKit/Utility/YYAsyncLayer.m b/LEEThemeDemo/LEEThemeDemo/Librarys/YYKit/Utility/YYAsyncLayer.m index 2768ae6..b9b78c1 100755 --- a/LEEThemeDemo/LEEThemeDemo/Librarys/YYKit/Utility/YYAsyncLayer.m +++ b/LEEThemeDemo/LEEThemeDemo/Librarys/YYKit/Utility/YYAsyncLayer.m @@ -190,28 +190,32 @@ - (void)_displayAsync:(BOOL)async { } else { [_sentinel increase]; if (task.willDisplay) task.willDisplay(self); - UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale); - CGContextRef context = UIGraphicsGetCurrentContext(); - if (self.opaque) { - CGSize size = self.bounds.size; - size.width *= self.contentsScale; - size.height *= self.contentsScale; - CGContextSaveGState(context); { - if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) { - CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); - CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); - CGContextFillPath(context); - } - if (self.backgroundColor) { - CGContextSetFillColorWithColor(context, self.backgroundColor); - CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); - CGContextFillPath(context); - } - } CGContextRestoreGState(context); - } - task.display(context, self.bounds.size, ^{return NO;}); - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); + UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init]; + format.opaque = self.opaque; + format.scale = self.contentsScale; + + UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.bounds.size format:format]; + UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) { + CGContextRef context = rendererContext.CGContext; + if (self.opaque) { + CGSize size = self.bounds.size; + size.width *= self.contentsScale; + size.height *= self.contentsScale; + CGContextSaveGState(context); { + if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) { + CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); + CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); + CGContextFillPath(context); + } + if (self.backgroundColor) { + CGContextSetFillColorWithColor(context, self.backgroundColor); + CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); + CGContextFillPath(context); + } + } CGContextRestoreGState(context); + } + task.display(context, self.bounds.size, ^{return NO;}); + }]; self.contents = (__bridge id)(image.CGImage); if (task.didDisplay) task.didDisplay(self, YES); } diff --git a/UPDATELOG.md b/UPDATELOG.md index bc27e7b..0c10ddf 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -1,6 +1,10 @@ # LEETheme - 更新日志 +V1.2.2 +============== +增加图片缓存 + V1.2.1 ============== 添加隐私清单