Created
September 23, 2015 18:41
-
-
Save joelcox/28de2f0cb21ea47bd789 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
NSColor.selectedMenuItemColor().set() | |
NSRectFillUsingOperation(dirtyRect, .CompositeSourceOver); | |
if (dirtyRect.size.height > 1) { | |
let heightMinus1 = dirtyRect.size.height - 1 | |
let currentControlTint = NSColor.currentControlTint() | |
var startingOpacity: CGFloat = 0.09 | |
if currentControlTint == .BlueControlTint { | |
startingOpacity = 0.16 | |
} | |
var 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
Thanks! - I tightened it up a bit to remove some
var
s - https://gist.github.com/orta/cfe35d71b8477ac20d02a4da11e7e0d2