Created
August 10, 2018 16:28
-
-
Save getaclue00/27af63dcf34d0d446241cd5a81427470 to your computer and use it in GitHub Desktop.
RoundedTextFieldCell
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
// | |
// 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