Skip to content

Instantly share code, notes, and snippets.

@zyuanming
Created August 1, 2017 08:53
Show Gist options
  • Select an option

  • Save zyuanming/58a517b28d8f0f73847b641058ca4e9f to your computer and use it in GitHub Desktop.

Select an option

Save zyuanming/58a517b28d8f0f73847b641058ca4e9f to your computer and use it in GitHub Desktop.
RoundImage.swift
private func strokedRoundImage(fromImage image: UIImage?,
size: CGSize,
color: UIColor,
lineWidth: CGFloat = 1.0) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
defer { UIGraphicsEndImageContext() }
let innerRect = CGRect(x: 1.0, y: 1.0, width: size.width - 2.0, height: size.height - 2.0)
image?.draw(in: innerRect)
let circle = UIBezierPath(ovalIn: innerRect)
color.setStroke()
circle.lineWidth = lineWidth
circle.stroke()
return UIGraphicsGetImageFromCurrentImageContext()?.withRenderingMode(.alwaysOriginal)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment