Skip to content

Instantly share code, notes, and snippets.

@getaclue00
Created August 10, 2018 16:28
Show Gist options
  • Save getaclue00/27af63dcf34d0d446241cd5a81427470 to your computer and use it in GitHub Desktop.
Save getaclue00/27af63dcf34d0d446241cd5a81427470 to your computer and use it in GitHub Desktop.
RoundedTextFieldCell
//
// RoundedNSTextFieldCell.swift
//
// https://stackoverflow.com/a/40065608
import Cocoa
class RoundedTextFieldCell: NSTextFieldCell {
@IBInspectable var borderColor: NSColor = .clear
@IBInspectable var cornerRadius: CGFloat = 3
override func draw(withFrame cellFrame: NSRect, in controlView: NSView) {
let bounds = NSBezierPath(roundedRect: cellFrame, xRadius: cornerRadius, yRadius: cornerRadius)
bounds.addClip()
super.draw(withFrame: cellFrame, in: controlView)
if borderColor != .clear {
bounds.lineWidth = 2
borderColor.setStroke()
bounds.stroke()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment