Add NSImage extension method to tint an image with a color.

This commit is contained in:
Brent Simmons 2017-12-17 10:48:24 -08:00
parent 587ae2d1db
commit adf5a5e784
2 changed files with 32 additions and 0 deletions

View File

@ -71,6 +71,7 @@
842E45CC1ED623C7000A8B52 /* UniqueIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45CB1ED623C7000A8B52 /* UniqueIdentifier.swift */; }; 842E45CC1ED623C7000A8B52 /* UniqueIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45CB1ED623C7000A8B52 /* UniqueIdentifier.swift */; };
8432B1861DACA0E90057D6DF /* NSResponder-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8432B1851DACA0E90057D6DF /* NSResponder-Extensions.swift */; }; 8432B1861DACA0E90057D6DF /* NSResponder-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8432B1851DACA0E90057D6DF /* NSResponder-Extensions.swift */; };
8432B1881DACA2060057D6DF /* NSWindow-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8432B1871DACA2060057D6DF /* NSWindow-Extensions.swift */; }; 8432B1881DACA2060057D6DF /* NSWindow-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8432B1871DACA2060057D6DF /* NSWindow-Extensions.swift */; };
84411E731FE5FFC3004B527F /* NSImage+RSCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84411E721FE5FFC3004B527F /* NSImage+RSCore.swift */; };
844C915B1B65753E0051FC1B /* RSPlist.h in Headers */ = {isa = PBXBuildFile; fileRef = 844C91591B65753E0051FC1B /* RSPlist.h */; settings = {ATTRIBUTES = (Public, ); }; }; 844C915B1B65753E0051FC1B /* RSPlist.h in Headers */ = {isa = PBXBuildFile; fileRef = 844C91591B65753E0051FC1B /* RSPlist.h */; settings = {ATTRIBUTES = (Public, ); }; };
844C915C1B65753E0051FC1B /* RSPlist.m in Sources */ = {isa = PBXBuildFile; fileRef = 844C915A1B65753E0051FC1B /* RSPlist.m */; }; 844C915C1B65753E0051FC1B /* RSPlist.m in Sources */ = {isa = PBXBuildFile; fileRef = 844C915A1B65753E0051FC1B /* RSPlist.m */; };
844F91D51D90D86100820C48 /* RSTransparentContainerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 844F91D31D90D86100820C48 /* RSTransparentContainerView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 844F91D51D90D86100820C48 /* RSTransparentContainerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 844F91D31D90D86100820C48 /* RSTransparentContainerView.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -189,6 +190,7 @@
842E45CB1ED623C7000A8B52 /* UniqueIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniqueIdentifier.swift; sourceTree = "<group>"; }; 842E45CB1ED623C7000A8B52 /* UniqueIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniqueIdentifier.swift; sourceTree = "<group>"; };
8432B1851DACA0E90057D6DF /* NSResponder-Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSResponder-Extensions.swift"; sourceTree = "<group>"; }; 8432B1851DACA0E90057D6DF /* NSResponder-Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSResponder-Extensions.swift"; sourceTree = "<group>"; };
8432B1871DACA2060057D6DF /* NSWindow-Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSWindow-Extensions.swift"; sourceTree = "<group>"; }; 8432B1871DACA2060057D6DF /* NSWindow-Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSWindow-Extensions.swift"; sourceTree = "<group>"; };
84411E721FE5FFC3004B527F /* NSImage+RSCore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "NSImage+RSCore.swift"; path = "Images/NSImage+RSCore.swift"; sourceTree = "<group>"; };
844C91591B65753E0051FC1B /* RSPlist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSPlist.h; path = RSCore/RSPlist.h; sourceTree = "<group>"; }; 844C91591B65753E0051FC1B /* RSPlist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSPlist.h; path = RSCore/RSPlist.h; sourceTree = "<group>"; };
844C915A1B65753E0051FC1B /* RSPlist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSPlist.m; path = RSCore/RSPlist.m; sourceTree = "<group>"; }; 844C915A1B65753E0051FC1B /* RSPlist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSPlist.m; path = RSCore/RSPlist.m; sourceTree = "<group>"; };
844F91D31D90D86100820C48 /* RSTransparentContainerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSTransparentContainerView.h; sourceTree = "<group>"; }; 844F91D31D90D86100820C48 /* RSTransparentContainerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSTransparentContainerView.h; sourceTree = "<group>"; };
@ -468,6 +470,7 @@
84CFF5631AC3D13C00CEA6C8 /* RSImageRenderer.m */, 84CFF5631AC3D13C00CEA6C8 /* RSImageRenderer.m */,
84CFF5671AC3D1B000CEA6C8 /* RSScaling.h */, 84CFF5671AC3D1B000CEA6C8 /* RSScaling.h */,
84CFF5681AC3D1B000CEA6C8 /* RSScaling.m */, 84CFF5681AC3D1B000CEA6C8 /* RSScaling.m */,
84411E721FE5FFC3004B527F /* NSImage+RSCore.swift */,
); );
name = Images; name = Images;
path = RSCore; path = RSCore;
@ -771,6 +774,7 @@
8461387F1DB3F5BE00048B83 /* RSToolbarItem.swift in Sources */, 8461387F1DB3F5BE00048B83 /* RSToolbarItem.swift in Sources */,
84B99C941FAE64D500ECDEDB /* DisplayNameProvider.swift in Sources */, 84B99C941FAE64D500ECDEDB /* DisplayNameProvider.swift in Sources */,
84BB45431D6909C700B48537 /* NSMutableDictionary-Extensions.swift in Sources */, 84BB45431D6909C700B48537 /* NSMutableDictionary-Extensions.swift in Sources */,
84411E731FE5FFC3004B527F /* NSImage+RSCore.swift in Sources */,
845DE0F41B80477100D1571B /* NSSet+RSCore.m in Sources */, 845DE0F41B80477100D1571B /* NSSet+RSCore.m in Sources */,
842635591D7FA24800196285 /* NSOutlineView+Extensions.swift in Sources */, 842635591D7FA24800196285 /* NSOutlineView+Extensions.swift in Sources */,
844C915C1B65753E0051FC1B /* RSPlist.m in Sources */, 844C915C1B65753E0051FC1B /* RSPlist.m in Sources */,

View File

@ -0,0 +1,28 @@
//
// NSImage+RSCore.swift
// RSCore
//
// Created by Brent Simmons on 12/16/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
//
import Cocoa
public extension NSImage {
public func tinted(with color: NSColor) -> NSImage {
let image = self.copy() as! NSImage
image.lockFocus()
color.set()
let rect = NSRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
rect.fill(using: .sourceAtop)
image.unlockFocus()
image.isTemplate = false
return image
}
}