#define dotW 4.5
#define activeDotW 6
#define magrin 5
重寫UIPagecontrol類,添加下面方法根據(jù)需求修改間距
- (void)layoutSubviews
{
[super layoutSubviews];
//計算圓點間距
CGFloat marginX = dotW + magrin - 1;
//計算整個pageControll的寬度
CGFloat newW = (self.subviews.count - 1 ) * marginX;
//設(shè)置新frame
self.frame = CGRectMake(SCREEN_WIDTH - newW - 20, self.frame.origin.y, newW, self.frame.size.height);
//設(shè)置居中
//? ? CGPoint center = self.center;
//? ? center.x = self.superview.center.x;
//? ? self.center = center;
//遍歷subview,設(shè)置圓點frame
for (int i=0; i<[self.subviews count]; i++) {
UIImageView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage) {
[dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dotW)];
}else {
[dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dotW)];
}
}
}