nicklockwood / FXPageControl

Simple, drop-in replacement for the iPhone UIPageControl that allows customisation of the dot colour, size and spacing.
Other
298 stars 69 forks source link

CGPath misplaced #17

Open cepages opened 8 years ago

cepages commented 8 years ago

I'm using FXPageControl with iOS 9 with CGPath:

self.pagecontrol.numberOfPages = self.maxIndex;
    self.pagecontrol.currentPage = self.index;

    int widthPageControl = (self.pagecontrol.bounds.size.width - ((self.maxIndex - 1) * SPACING_PAGE_CONTROL) ) / self.maxIndex;

    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, CGRectMake(0, 0, widthPageControl, HEIGHT_PAGE_CONTROL));
    CGPathCloseSubpath(path);
    self.pagecontrol.dotShape = path;
    self.pagecontrol.dotSize = widthPageControl;
    self.pagecontrol.dotColor = [UIColor blueColor];
    self.pagecontrol.dotSpacing = SPACING_PAGE_CONTROL;

    self.pagecontrol.selectedDotShape = path;
    self.pagecontrol.selectedDotSize = widthPageControl;
    self.pagecontrol.selectedDotColor = [UIColor orangeColor];

    CGPathRelease(path);

The interesting thing is the first CGPath is misplaced and diving in the code I found this is the problem:

      CGFloat offset = (_dotSize + _dotSpacing) * i + _dotSize / 2;

so changing this to:

      CGFloat offset = (_dotSize + _dotSpacing) * i;

Why do you need all the time _dotSize / 2?

Images with _dotSize / 2;

screen shot 2016-09-05 at 16 42 11 screen shot 2016-09-05 at 16 42 27