Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swift implementation to highlight Cocoa UI elements (http://stackoverflow.com/a/25984748/316803)
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)
}
}
@orta

This comment has been minimized.

Copy link

orta commented Apr 23, 2016

Thanks! - I tightened it up a bit to remove some vars - https://gist.github.com/orta/cfe35d71b8477ac20d02a4da11e7e0d2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.