92 lines
4.2 KiB
Objective-C
92 lines
4.2 KiB
Objective-C
//
|
|
// UIImage+load.m
|
|
// YM
|
|
//
|
|
// Created by YM on 2023/1/8.
|
|
//
|
|
//
|
|
|
|
#import "UIImage+load.h"
|
|
#import <objc/runtime.h>
|
|
|
|
@implementation UIImage (load)
|
|
+ (void)load{
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^{
|
|
[UIImage yumi_swizzleInstanceMethod:[UIImage class] original:@selector(imageNamed:) swizzled:@selector(imgesNameHook:)];
|
|
if (@available(iOS 13.0, *)) {
|
|
[UIImage yumi_swizzleInstanceMethod:[UIImage class] original:@selector(imageNamed:inBundle:withConfiguration:) swizzled:@selector(yumi_imgename:inBundle:withConfiguration:)];
|
|
}
|
|
[UIImage yumi_swizzleInstanceMethod:[UIImage class] original:@selector(imageNamed:inBundle:compatibleWithTraitCollection:) swizzled:@selector(yumi_imgename:inBundle:compatibleWithTraitCollection:)];
|
|
});
|
|
}
|
|
+ (void)yumi_swizzleInstanceMethod:(Class)target original:(SEL)originalSelector swizzled:(SEL)swizzledSelector {
|
|
Method originMethod = class_getClassMethod(target, originalSelector);
|
|
Method swizzledMethod = class_getClassMethod(target, swizzledSelector);
|
|
method_exchangeImplementations(originMethod, swizzledMethod);
|
|
}
|
|
|
|
+ (UIImage *)yumi_imgename:(NSString *)name inBundle:(NSBundle *)bundle compatibleWithTraitCollection:(UITraitCollection *)traitCollection {
|
|
UIImage *img = [self yumi_imgename:name inBundle:bundle compatibleWithTraitCollection:traitCollection];
|
|
if (!img&& bundle!= nil) {
|
|
img = [self imageNamed:name];
|
|
}
|
|
return img;
|
|
}
|
|
|
|
+ (UIImage *)yumi_imgename:(NSString *)name inBundle:(NSBundle *)bundle withConfiguration:(UIImageConfiguration *)configuration API_AVAILABLE(ios(13.0)){
|
|
UIImage *img = [self yumi_imgename:name inBundle:bundle withConfiguration:configuration];
|
|
if (!img && bundle!= nil) {
|
|
img = [self imageNamed:name];
|
|
}
|
|
return img;
|
|
}
|
|
|
|
+ (UIImage *)imgesNameHook:(NSString *)name{
|
|
UIImage *temp = [UIImage imgesNameHook:name];
|
|
if (temp){
|
|
return temp;
|
|
}
|
|
name = [self modifys:name];
|
|
temp = [UIImage imgesNameHook:name];
|
|
return temp;
|
|
}
|
|
|
|
+ (NSString *)modifys:(NSString *)name{
|
|
name = [name stringByReplacingOccurrencesOfString:@"ic_" withString:@"image_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"_bg" withString:@"_background"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"_icon" withString:@"_pic"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"gift_" withString:@"present_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"bar_" withString:@"let_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"tag_" withString:@"label"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"info_" withString:@"gen_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"room_" withString:@"scope_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"message_" withString:@"msg_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"session_" withString:@"term_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"content_" withString:@"matter_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"tool_" withString:@"kit_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"home_" withString:@"main_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"live_" withString:@"spot_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"nav_" withString:@"title_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"mine_" withString:@"center_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"noble_" withString:@"grand_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"rank_" withString:@"order_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"common_" withString:@"same_"];
|
|
name = [name stringByReplacingOccurrencesOfString:@"share_" withString:@"parti_"];
|
|
if ([name hasPrefix:@"yumi_"] == NO){
|
|
name = [NSString stringWithFormat:@"yumi_%@",name];
|
|
}
|
|
return name;
|
|
|
|
}
|
|
|
|
+ (NSString *)changeFiles:(NSString *)path {
|
|
NSString *basePath = [path stringByDeletingLastPathComponent];
|
|
NSString *lastPath = [path lastPathComponent];
|
|
NSString *replaceName = [self modifys:lastPath];
|
|
return [basePath stringByAppendingPathComponent:replaceName];
|
|
}
|
|
|
|
//}
|
|
@end
|