diff --git a/FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift b/FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift index 710aca7..cd3ae89 100644 --- a/FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift +++ b/FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift @@ -11,7 +11,7 @@ import UIKit class PageControlExampleViewController: UIViewController,UITableViewDataSource,UITableViewDelegate,FSPagerViewDataSource,FSPagerViewDelegate { fileprivate let imageNames = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg"] - fileprivate let pageControlStyles = ["Default", "Ring", "UIImage", "UIBezierPath - Star", "UIBezierPath - Heart"] + fileprivate let pageControlStyles = ["Default", "Ring", "UIImage", "UIBezierPath - Star", "UIBezierPath - Heart", "Circle not same Width"] fileprivate let pageControlAlignments = ["Right", "Center", "Left"] fileprivate let sectionTitles = ["Style", "Item Spacing", "Interitem Spacing", "Horizontal Alignment"] @@ -54,6 +54,13 @@ class PageControlExampleViewController: UIViewController,UITableViewDataSource,U self.pageControl.setFillColor(color, for: .selected) self.pageControl.setPath(self.heartPath, for: .normal) self.pageControl.setPath(self.heartPath, for: .selected) + case 5: + self.pageControl.setPath(UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 8, height: 8), cornerRadius: 4), for: .normal) + self.pageControl.setPath(UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 12, height: 8), cornerRadius: 4), for: .selected) + self.pageControl.setStrokeColor(.red, for: .normal) + self.pageControl.setStrokeColor(.blue, for: .selected) + self.pageControl.setFillColor(.red, for: .normal) + self.pageControl.setFillColor(.blue, for: .selected) default: break } diff --git a/Sources/FSPageControl.swift b/Sources/FSPageControl.swift index e3bd745..4e73c28 100644 --- a/Sources/FSPageControl.swift +++ b/Sources/FSPageControl.swift @@ -112,6 +112,15 @@ open class FSPageControl: UIControl { return 0 case .center, .fill: let midX = self.contentView.bounds.midX + if let norImage = self.images[.normal], let selImage = self.images[.selected] { + let totalWidth = CGFloat((numberOfPages - 1)) * (norImage.size.width + spacing) + selImage.size.width + let amplitude = (self.contentView.bounds.width - totalWidth) / 2.0 + return amplitude + } else if let norPath = self.paths[.normal], let selPath = self.paths[.selected] { + let totalWidth = CGFloat((numberOfPages - 1)) * (norPath.bounds.size.width + spacing) + selPath.bounds.size.width + let amplitude = (self.contentView.bounds.width - totalWidth) / 2.0 + return amplitude + } let amplitude = CGFloat(self.numberOfPages/2) * diameter + spacing*CGFloat((self.numberOfPages-1)/2) return midX - amplitude case .right, .trailing: @@ -125,9 +134,15 @@ open class FSPageControl: UIControl { let state: UIControl.State = (index == self.currentPage) ? .selected : .normal let image = self.images[state] let size = image?.size ?? CGSize(width: diameter, height: diameter) - let origin = CGPoint(x: x - (size.width-diameter)*0.5, y: self.contentView.bounds.midY-size.height*0.5) + let origin = CGPoint(x: x, y: self.contentView.bounds.midY-size.height*0.5) value.frame = CGRect(origin: origin, size: size) - x = x + spacing + diameter + if let image = self.images[state] { + x = x + spacing + image.size.width + } else if let path = self.paths[state] { + x = x + spacing + path.bounds.size.width + } else { + x = x + spacing + diameter + } } }