Skip to content

Commit

Permalink
Convert NSImageView tint color as variable setter (#5)
Browse files Browse the repository at this point in the history
* Updated the README file to provide information about guidelines and enhancements
Added support for CollectionViews, TextField and Labels
Added ActivityIndicatorView support
Provide mechanism to apply tintColor to NSUIImageView

* Fix alias error for UICollectionViewCell

* Moving NSUIImageView to the proper Aliases.swift file

* Make tintColor a variable setter for NSUIImageView(AppKit) as to not break UIKit logic.
  • Loading branch information
martindufort authored Dec 29, 2023
1 parent 04d5572 commit cd08c57
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Sources/NSUI/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ import SwiftUI

#if canImport(AppKit)
public extension NSImageView {
func tintColor(color: NSUIColor) {
guard
let selfImage = self.image
else { return }
let image = NSImage(size: selfImage.size, flipped: false) { (rect) -> Bool in
color.set()
rect.fill()
selfImage.draw(in: rect, from: NSRect(origin: .zero, size: selfImage.size), operation: .destinationIn, fraction: 1.0)
return true
var tintColor: NSUIColor {
@available(*, unavailable)
get {
fatalError("Unavailable")
}
set {
guard
let selfImage = self.image
else {
return
}
let image = NSImage(size: selfImage.size, flipped: false) { (rect) -> Bool in
newValue.set()
rect.fill()
selfImage.draw(in: rect, from: NSRect(origin: .zero, size: selfImage.size), operation: .destinationIn, fraction: 1.0)
return true
}
self.image = image
}
self.image = image
}
}
#endif

0 comments on commit cd08c57

Please sign in to comment.