改变三方库SDCycleScrollView中PageControl大小

#import 

#import 

NS_ASSUME_NONNULL_BEGIN

@interface TAPageControl (PSStyle)

@end

NS_ASSUME_NONNULL_END
#import "TAPageControl+PSStyle.h"
#import 

@implementation TAPageControl (PSStyle)

+ (void)load {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];
        
        SEL originalSelector = @selector(changeActivity:atIndex:);
        SEL swizzledSelector = @selector(myChangeActivity:atIndex:);
        
        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzleMethod = class_getInstanceMethod(class, swizzledSelector);
        
        BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzleMethod),method_getTypeEncoding(originalMethod));
        
        if (didAddMethod) {
            class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzleMethod);
        }
    });
}

- (void)myChangeActivity:(BOOL)active atIndex:(NSInteger)index {
    if (self.dotViewClass) {
        TAAbstractDotView *abstractDotView = (TAAbstractDotView *)[self.subviews objectAtIndex:index];
        if ([abstractDotView respondsToSelector:@selector(changeActivityState:)]) {
            [abstractDotView changeActivityState:active];
        } else {
            NSLog(@"Custom view:%@ must implement an 'changeActivityState' method for you can subclass  %@ to help you",self.dotViewClass, [TAAbstractDotView class]);
        }
    } else if (self.dotImage && self.currentDotImage) {
        UIImageView *dotView = (UIImageView *)[self.subviews objectAtIndex:index];
        dotView.image = (active) ? self.currentDotImage : self.dotImage;
        [self updateDotFrame:dotView atIndex:index];
        for (int i = 0; i < self.numberOfPages; i++) {
            UIImageView *tempDotView = (UIImageView *)[self.subviews objectAtIndex:i];
            [self updateDotFrame:tempDotView atIndex:i];
        }
    }
    
}

- (void)updateDotFrame:(UIView *)dot atIndex:(NSInteger)index {
    
    CGFloat x = (self.dotSize.width + self.spacingBetweenDots) * index + ( (CGRectGetWidth(self.frame) - [self sizeForNumberOfPages:self.numberOfPages].width) / 2);
    
    CGFloat y = (CGRectGetHeight(self.frame) - self.dotSize.height) / 2;
    
    
    if (index > self.currentPage) {
        x = (self.dotSize.width + self.spacingBetweenDots) * index + ( (CGRectGetWidth(self.frame) - [self sizeForNumberOfPages:self.numberOfPages].width) / 2) +self.currentDotImage.size.width - self.dotSize.width;
    }
    
    if (index == self.currentPage) {
        dot.frame = CGRectMake(x, 0, self.currentDotImage.size.width, self.currentDotImage.size.height);
    }else{
        dot.frame = CGRectMake(x, y, self.dotSize.width, self.dotSize.height);
    }
}

@end

你可能感兴趣的:(改变三方库SDCycleScrollView中PageControl大小)