FSPageControl的几种用法
2019-07-01 本文已影响0人
Boxzhi
-
选中为椭圆,非选中为圆,切宽度不一样
image.png
bannerControl = FSPageControl(frame: CGRect.zero)
bannerControl?.numberOfPages = 2
bannerControl?.contentHorizontalAlignment = .center
bannerControl?.contentInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
bannerControl?.setStrokeColor(UIColor(r: 117, g: 223, b: 172), for: .normal)
bannerControl?.setStrokeColor(.white, for: .selected)
bannerControl?.setFillColor(UIColor(r: 117, g: 223, b: 172), for: .normal)
bannerControl?.setFillColor(.white, for: .selected)
bannerControl?.interitemSpacing = 10
bannerControl?.setPath(UIBezierPath(roundedRect: CGRect(x: bannerControl!.itemSpacing / 2 - 6, y: 0, w: 12, h: 4), cornerRadius: 2), for: .selected)
bannerControl?.setPath(UIBezierPath(ovalIn: CGRect(x: bannerControl!.itemSpacing / 2 - 2, y: 0, w: 4, h: 4)), for: .normal)
-
选中非选中都为椭圆、宽高一样
image.png
let _pageControl = FSPageControl(frame: CGRect.zero)
_pageControl.numberOfPages = vcType.pageNumber
_pageControl.contentHorizontalAlignment = .left
_pageControl.contentInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0)
_pageControl.setStrokeColor(UIColor(r: 236, g: 237, b: 241), for: .normal)
_pageControl.setStrokeColor(UIColor(r: 160, g: 165, b: 187), for: .selected)
_pageControl.setFillColor(UIColor(r: 236, g: 237, b: 241), for: .normal)
_pageControl.setFillColor(UIColor(r: 160, g: 165, b: 187), for: .selected)
_pageControl.interitemSpacing = 20
_pageControl.setPath(UIBezierPath(roundedRect: CGRect(x: 0, y: 0, w: 20, h: 3), cornerRadius: 1.5), for: .selected)
_pageControl.setPath(UIBezierPath(roundedRect: CGRect(x: 0, y: 0, w: 20, h: 3), cornerRadius: 1.5), for: .normal)
-
五角星⭐️
image.png
fileprivate var starPath: UIBezierPath {
let width = self.pageControl.itemSpacing
let height = self.pageControl.itemSpacing
let starPath = UIBezierPath()
starPath.move(to: CGPoint(x: width*0.5, y: 0))
starPath.addLine(to: CGPoint(x: width*0.677, y: height*0.257))
starPath.addLine(to: CGPoint(x: width*0.975, y: height*0.345))
starPath.addLine(to: CGPoint(x: width*0.785, y: height*0.593))
starPath.addLine(to: CGPoint(x: width*0.794, y: height*0.905))
starPath.addLine(to: CGPoint(x: width*0.5, y: height*0.8))
starPath.addLine(to: CGPoint(x: width*0.206, y: height*0.905))
starPath.addLine(to: CGPoint(x: width*0.215, y: height*0.593))
starPath.addLine(to: CGPoint(x: width*0.025, y: height*0.345))
starPath.addLine(to: CGPoint(x: width*0.323, y: height*0.257))
starPath.close()
return starPath
}
-
爱心❤️
image.png
fileprivate var heartPath: UIBezierPath {
let width = self.pageControl.itemSpacing
let height = self.pageControl.itemSpacing
let heartPath = UIBezierPath()
heartPath.move(to: CGPoint(x: width*0.5, y: height))
heartPath.addCurve(
to: CGPoint(x: 0, y: height*0.25),
controlPoint1: CGPoint(x: width*0.5, y: height*0.75) ,
controlPoint2: CGPoint(x: 0, y: height*0.5)
)
heartPath.addArc(
withCenter: CGPoint(x: width*0.25,y: height*0.25),
radius: width * 0.25,
startAngle: .pi,
endAngle: 0,
clockwise: true
)
heartPath.addArc(
withCenter: CGPoint(x: width*0.75, y: height*0.25),
radius: width * 0.25,
startAngle: .pi,
endAngle: 0,
clockwise: true
)
heartPath.addCurve(
to: CGPoint(x: width*0.5, y: height),
controlPoint1: CGPoint(x: width, y: height*0.5),
controlPoint2: CGPoint(x: width*0.5, y: height*0.75)
)
heartPath.close()
return heartPath
}