Skip to content

Commit

Permalink
For macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPodymov committed Jan 21, 2024
1 parent 2495acd commit ef0ed6c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/CommonAppleKit/CommonAppleKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,20 @@ public extension CAButton {
private extension CAImage {
func withTint(color: CAColor, newSize: CGSize? = nil) -> CAImage {
#if canImport(AppKit)
.init(size: size, flipped: false) { rect -> Bool in
.init(size: newSize ?? size, flipped: false) { rect -> Bool in
color.set()
rect.fill()
self.draw(in: rect, from: .init(origin: .zero, size: self.size), operation: .destinationIn, fraction: 1.0)
self.draw(
in: .init(origin: rect.origin, size: newSize ?? rect.size),
from: .init(origin: .zero, size: self.size),
operation: .destinationIn,
fraction: 1.0
)
return true
}
#elseif canImport(UIKit)
defer { UIGraphicsEndImageContext() }
let sizeToUse = newSize ?? size
defer { UIGraphicsEndImageContext() }
UIGraphicsBeginImageContextWithOptions(sizeToUse, false, scale)
color.set()
withRenderingMode(.alwaysTemplate).draw(in: CGRect(origin: .zero, size: sizeToUse))
Expand Down

0 comments on commit ef0ed6c

Please sign in to comment.