-
-
Save orta/cfe35d71b8477ac20d02a4da11e7e0d2 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 hidden or 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() | |
NSRectFillUsingOperation(dirtyRect, .CompositeSourceOver); | |
if (dirtyRect.size.height > 1) { | |
let heightMinus1 = dirtyRect.size.height - 1 | |
let currentControlTint = NSColor.currentControlTint() | |
let startingOpacity: CGFloat = currentControlTint == .BlueControlTint ? 0.16 : 0.09 | |
let gradient = NSGradient(startingColor: NSColor(white: CGFloat(1.0), alpha:startingOpacity), endingColor:NSColor(white: CGFloat(1.0), alpha: 0.0))! | |
let startPoint = NSMakePoint(dirtyRect.origin.x, dirtyRect.origin.y + heightMinus1) | |
let endPoint = NSMakePoint(dirtyRect.origin.x, dirtyRect.origin.y + 1) | |
gradient.drawFromPoint(startPoint, toPoint: endPoint, options:NSGradientDrawsBeforeStartingLocation) | |
if currentControlTint == .BlueControlTint { | |
NSColor(white: CGFloat(1.0), alpha: CGFloat(0.1)).set() | |
let smallerRect = NSMakeRect(dirtyRect.origin.x, dirtyRect.origin.y + heightMinus1, dirtyRect.size.width, CGFloat(1.0)) | |
NSRectFillUsingOperation(smallerRect, .CompositeSourceOver) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for Swift 5 and modern types: https://gist.github.com/soffes/6a305de23f5663cf0e27f4b338606a3b
This doesn't match on Mojave though.