方法一:使用runtime,替换控件私有方法
#import <objc/runtime.h>
+ (void)load
{
Method origin = class_getInstanceMethod([self class], @selector(_indicatorSpacing));
Method custom = class_getInstanceMethod([self class], @selector(custom_indicatorSpacing));
method_exchangeImplementations(origin, custom);
}
- (double)custom_indicatorSpacing
{
return 6.0;
}
注意:这种方法因为调用私有API过不了app store 审核。
方法二:使用遍历控件的所有子视图,重设所有子视图的frame
- (void)setCurrentPage:(NSInteger)page {
NSUInteger magrin = 5;
NSUInteger count = [self.subviews count];
NSUInteger firstX = 0;
CGSize size;
size.height = 5;
size.width = 5;
firstX = (self.frame.size.width-size.width*count-magrin*(count-1))/2;
for (NSUInteger i = 0; i < count; i++) {
UIImageView* subview = [self.subviews objectAtIndex:i];
[subview setFrame:CGRectMake(firstX+(size.width + magrin)*i, subview.frame.origin.y, size.width,size.height)];
}
}
参考:
http://www.cnblogs.com/chyl411/p/5421668.html
https://zhidao.baidu.com/question/563396477476563524.html