Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
fix: sharpen blurry icons across the app (#1488)
Browse files Browse the repository at this point in the history
Fix the `image(with color)` extension method so it does not scale the image incorrectly.  The new implementation uses an imageView to render the new image.
  • Loading branch information
colinbrash authored and saeedbashir committed Apr 9, 2021
1 parent 5af57de commit f0f3429
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Source/UIImage+OEXHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ extension UIImage {
}

func image(with color: UIColor) -> UIImage {
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
if let cgImage = cgImage {
context?.clip(to: rect, mask: cgImage)
let image = withRenderingMode(.alwaysTemplate)
let imageView = UIImageView(image: image)
imageView.tintColor = color

var tintedImage: UIImage?
UIGraphicsBeginImageContextWithOptions(image.size, false, 0.0)
if let context = UIGraphicsGetCurrentContext() {
imageView.layer.render(in: context)
tintedImage = UIGraphicsGetImageFromCurrentImageContext()
}
context?.setFillColor(color.cgColor)
context?.fill(rect)
UIGraphicsEndImageContext()

if let cgImage = UIGraphicsGetImageFromCurrentImageContext()?.cgImage {
UIGraphicsEndImageContext()
return UIImage(cgImage: cgImage, scale: 1, orientation: .downMirrored)
if let tintedImage = tintedImage {
return tintedImage
} else {
return self
}
Expand Down

0 comments on commit f0f3429

Please sign in to comment.