美文网首页
iOS修改系统pagecontrol间距

iOS修改系统pagecontrol间距

作者: 短发控丶kk | 来源:发表于2016-12-29 12:07 被阅读0次

#define dotW 4.5

#define activeDotW 6

#define magrin 5

重写UIPagecontrol类,添加下面方法根据需求修改间距

- (void)layoutSubviews

{

[super layoutSubviews];

//计算圆点间距

CGFloat marginX = dotW + magrin - 1;

//计算整个pageControll的宽度

CGFloat newW = (self.subviews.count - 1 ) * marginX;

//设置新frame

self.frame = CGRectMake(SCREEN_WIDTH - newW - 20, self.frame.origin.y, newW, self.frame.size.height);

//设置居中

//    CGPoint center = self.center;

//    center.x = self.superview.center.x;

//    self.center = center;

//遍历subview,设置圆点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)];

}

}

}

相关文章

网友评论

      本文标题:iOS修改系统pagecontrol间距

      本文链接:https://www.haomeiwen.com/subject/krouvttx.html