PlaceholderKit/Source/NSImage+Placeholder.swift

23 lines
503 B
Swift

//
// NSImage+Placeholder.swift
// PlaceholderKit
//
// Created by Simon Lee on 12/12/18.
// Copyright © 2018 Shao Ping Lee. All rights reserved.
//
#if canImport(AppKit)
import AppKit
extension NSImage {
static func createPlaceholder(withColor color: NSColor, size: CGSize) -> NSImage? {
let image = NSImage(size: size)
image.lockFocus()
color.drawSwatch(in: NSMakeRect(0, 0, size.width, size.height))
image.unlockFocus()
return image
}
}
#endif