Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 一个分类(防止标签的tag值重名不能展示fps) #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions JPFPSStatus/JPFPSStatus/JPFPSStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 <UIApplicationDelegate> *)([UIApplication sharedApplication].delegate)) window].rootViewController.view addSubview:fpsLabel];
Expand All @@ -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;
}
Expand Down