UIPageControl+LhGray.m
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// UIPageControl+LhGray.m
// SmartCity
//
// Created by luoh on 2021/3/25.
// Copyright © 2021 StarHome. All rights reserved.
//
#import "UIPageControl+LhGray.h"
#import <objc/runtime.h>
@implementation UIPageControl (LhGray)
+(void)lh_pageControlSwizzldMethedWith:(BOOL)changeGray{
if (changeGray == false) {
return;
}
Class cls = [self class];
SEL oriSel = @selector(setCurrentPageIndicatorTintColor:);
SEL swizzldSel = @selector(lh_setCurrentPageIndicatorTintColor:);
Method originMethed = class_getInstanceMethod(cls, oriSel);
Method swizzldMethed = class_getInstanceMethod(cls, swizzldSel);
BOOL isAddMethed = class_addMethod(cls, oriSel, method_getImplementation(swizzldMethed),method_getTypeEncoding(swizzldMethed));
if (isAddMethed) {
class_replaceMethod(cls, swizzldSel, method_getImplementation(originMethed), method_getTypeEncoding(originMethed));
}else{
method_exchangeImplementations(originMethed,swizzldMethed);
}
}
-(void)lh_setCurrentPageIndicatorTintColor:(UIColor *)color{
UIColor * newColor = [self changeGrayWithColor:color Red:1.0 green:0.0 blue:0.0 alpha:1.0];
[self lh_setCurrentPageIndicatorTintColor:newColor];
}
- (UIColor *)changeGrayWithColor:(UIColor *)color Red:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b alpha:(CGFloat)a {
CGFloat gray = r * 0.299 +g * 0.587 + b * 0.114;
UIColor *grayColor = [UIColor colorWithWhite:gray alpha:a];
return grayColor;
}
@end