-
-
Save soffes/6a305de23f5663cf0e27f4b338606a3b to your computer and use it in GitHub Desktop.
Swift implementation to highlight Cocoa UI elements (http://stackoverflow.com/a/25984748/316803)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from: | |
// https://gist.github.com/joelcox/28de2f0cb21ea47bd789 | |
NSColor.selectedMenuItemColor.set() | |
NSBezierPath(rect: rect).fill() | |
if rect.height > 1 { | |
let currentControlTint = NSColor.currentControlTint | |
let startingAlpha: CGFloat = currentControlTint == .blueControlTint ? 0.16 : 0.09 | |
let gradient = NSGradient(starting: NSColor(white: 1, alpha: startingAlpha), | |
ending: NSColor(white: 1, alpha: 0)) | |
let start = CGPoint(x: rect.minX, y: rect.maxY - 1) | |
let end = CGPoint(x: rect.minX, y: rect.minY + 1) | |
gradient?.draw(from: start, to: end, options: .drawsBeforeStartingLocation) | |
if currentControlTint == .blueControlTint { | |
NSColor(white: 1, alpha: 0.1).set() | |
let smallerRect = CGRect(x: rect.minX, y: rect.maxY - 1, width: rect.width, height: 1) | |
NSBezierPath(rect: smallerRect).fill() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment