diff --git a/JPFPSStatus/JPFPSStatus/JPFPSStatus.m b/JPFPSStatus/JPFPSStatus/JPFPSStatus.m index 84cb519..a4e8aaa 100644 --- a/JPFPSStatus/JPFPSStatus/JPFPSStatus.m +++ b/JPFPSStatus/JPFPSStatus/JPFPSStatus.m @@ -7,6 +7,29 @@ // @ https://github.com/joggerplus/JPFPSStatus #import "JPFPSStatus.h" +#import "objc/runtime.h" + +static const void *JPFPSCustomTagKey = &JPFPSCustomTagKey; +@interface UIView (JPFPSCustomTag) + +@property(nonatomic) NSInteger customTag; // default is 0 + +@end + +@implementation UIView (JPFPSCustomTag) + +- (void) setCustomTag:(NSInteger)customTag +{ + objc_setAssociatedObject(self, JPFPSCustomTagKey, @(customTag), OBJC_ASSOCIATION_RETAIN); +} + +- (NSInteger) customTag +{ + NSNumber *cTagNumber = objc_getAssociatedObject(self, JPFPSCustomTagKey); + cTagNumber = cTagNumber ? : cTagNumber; + return cTagNumber.integerValue; +} +@end @interface JPFPSStatus (){ CADisplayLink *displayLink; @@ -58,7 +81,7 @@ - (id)init { fpsLabel.textColor=[UIColor colorWithRed:0.33 green:0.84 blue:0.43 alpha:1.00]; fpsLabel.backgroundColor=[UIColor clearColor]; fpsLabel.textAlignment=NSTextAlignmentRight; - fpsLabel.tag=101; + fpsLabel.customTag=101; } return self; @@ -86,13 +109,6 @@ - (void)displayLinkTick:(CADisplayLink *)link { } - (void)open { - - NSArray *rootVCViewSubViews=[[UIApplication sharedApplication].delegate window].rootViewController.view.subviews; - for (UIView *label in rootVCViewSubViews) { - if ([label isKindOfClass:[UILabel class]]&& label.tag==101) { - return; - } - } [displayLink setPaused:NO]; [[((NSObject *)([UIApplication sharedApplication].delegate)) window].rootViewController.view addSubview:fpsLabel]; @@ -109,7 +125,7 @@ - (void)close { NSArray *rootVCViewSubViews=[[UIApplication sharedApplication].delegate window].rootViewController.view.subviews; for (UIView *label in rootVCViewSubViews) { - if ([label isKindOfClass:[UILabel class]]&& label.tag==101) { + if ([label isKindOfClass:[UILabel class]]&& label.customTag==101) { [label removeFromSuperview]; return; }