Skip to content

Instantly share code, notes, and snippets.

@kirqe
Created October 15, 2019 02:59
Show Gist options
  • Save kirqe/2472b350d079b48391b3be0beacf3930 to your computer and use it in GitHub Desktop.
Save kirqe/2472b350d079b48391b3be0beacf3930 to your computer and use it in GitHub Desktop.
Use color for selected NSTableRowView
import Cocoa
class ThreadsListItemRowView: NSTableRowView {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
if isSelected == true {
NSColor(hexFromString: "#ff9800").set()
dirtyRect.fill()
}
// Drawing code here.
}
}
extension NSColor {
convenience init(hexFromString:String, alpha:CGFloat = 1.0) {
var cString:String = hexFromString.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
var rgbValue:UInt32 = 10066329 //color #999999 if string has wrong format
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.count) == 6) {
Scanner(string: cString).scanHexInt32(&rgbValue)
}
self.init(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: alpha
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment