Skip to content

Commit

Permalink
Merge pull request #5 from welcommand/master
Browse files Browse the repository at this point in the history
fix bug && support imageName in IB
  • Loading branch information
yulingtianxia committed Apr 2, 2018
2 parents d257766 + 2713fed commit 9738045
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
10 changes: 4 additions & 6 deletions TBUIAutoTest/TBUIAutoTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,17 @@ @implementation NSObject (TBUIAutoTest)

+ (void)swizzleSelector:(SEL)originalSelector withAnotherSelector:(SEL)swizzledSelector
{
Class aClass = [self class];

Method originalMethod = class_getInstanceMethod(aClass, originalSelector);
Method swizzledMethod = class_getInstanceMethod(aClass, swizzledSelector);
Method originalMethod = class_getInstanceMethod(self, originalSelector);
Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector);

BOOL didAddMethod =
class_addMethod(aClass,
class_addMethod(self,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));

if (didAddMethod) {
class_replaceMethod(aClass,
class_replaceMethod(self,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
Expand Down
18 changes: 16 additions & 2 deletions TBUIAutoTest/UIImage+TBUIAutoTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "UIImage+TBUIAutoTest.h"
#import "TBUIAutoTest.h"
#import <objc/runtime.h>

@implementation UIImage (TBUIAutoTest)
+ (void)load
Expand All @@ -28,8 +29,9 @@ + (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self swizzleSelector:@selector(imageNamed:) withAnotherSelector:@selector(tb_imageNamed:)];
[self swizzleSelector:@selector(imageWithContentsOfFile:) withAnotherSelector:@selector(tb_imageWithContentsOfFile:)];
[object_getClass(self) swizzleSelector:@selector(imageNamed:) withAnotherSelector:@selector(tb_imageNamed:)];
[object_getClass(self) swizzleSelector:@selector(imageWithContentsOfFile:) withAnotherSelector:@selector(tb_imageWithContentsOfFile:)];
[self swizzleSelector:@selector(accessibilityIdentifier) withAnotherSelector:@selector(tb_accessibilityIdentifier)];
});
}

Expand Down Expand Up @@ -57,4 +59,16 @@ + (UIImage *)tb_imageWithContentsOfFile:(NSString *)path
return image;
}

- (id)assetName {return nil;}

- (NSString *)tb_accessibilityIdentifier {
NSString *tb_accessibilityIdentifier = [self tb_accessibilityIdentifier];
if (tb_accessibilityIdentifier.length == 0 && [self respondsToSelector:@selector(imageAsset)]) {
tb_accessibilityIdentifier = [(id)self.imageAsset assetName];
self.accessibilityIdentifier = tb_accessibilityIdentifier;
}

return tb_accessibilityIdentifier;
}

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -59,6 +79,16 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down

0 comments on commit 9738045

Please sign in to comment.