方法一:使用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;
}
注意:這種方法因?yàn)檎{(diào)用私有API過不了app store 審核蕉世。
方法二:使用遍歷控件的所有子視圖,重設(shè)所有子視圖的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