Skip to content

Instantly share code, notes, and snippets.

@tularovbeslan
Created August 4, 2017 11:02
Show Gist options
  • Save tularovbeslan/1a7bc23bc9dea99eda0a5d81be819957 to your computer and use it in GitHub Desktop.
Save tularovbeslan/1a7bc23bc9dea99eda0a5d81be819957 to your computer and use it in GitHub Desktop.
UIPageControl dot border
extension UIImage {
class func outlinedEllipse(size: CGSize, color: UIColor, lineWidth: CGFloat = 1.0) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}
context.setStrokeColor(color.cgColor)
context.setLineWidth(lineWidth)
let rect = CGRect(origin: .zero, size: size).insetBy(dx: lineWidth * 0.5, dy: lineWidth * 0.5)
context.addEllipse(in: rect)
context.strokePath()
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
//USE
let image = UIImage.outlinedEllipse(size: CGSize(width: 7.0, height: 7.0), color: .lightGray)
self.pageControl.pageIndicatorTintColor = UIColor.init(patternImage: image!)
self.pageControl.currentPageIndicatorTintColor = .lightGray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment