Created
August 1, 2017 08:53
-
-
Save zyuanming/58a517b28d8f0f73847b641058ca4e9f to your computer and use it in GitHub Desktop.
RoundImage.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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