Created
March 8, 2017 04:18
-
-
Save zpasternack/b8ae67901206bc6f80c9b0c65df8a8a8 to your computer and use it in GitHub Desktop.
Revisions
-
zpasternack created this gist
Mar 8, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ // Makes the text in an NSTextFieldCell vertically centered. Works with single line, non-editable cells. // Maybe doesn't work with others. // Stolen from this stackoverflow question: // http://stackoverflow.com/questions/1235219/is-there-a-right-way-to-have-nstextfieldcell-draw-vertically-centered-text import Cocoa class VerticallyCenteredTextFieldCell: NSTextFieldCell { override func titleRect(forBounds rect: NSRect) -> NSRect { var titleFrame = super.titleRect(forBounds: rect) let titleSize = self.attributedStringValue.size() titleFrame.origin.y = rect.origin.y + (rect.size.height - titleSize.height) / 2.0 return titleFrame } override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) { let titleRect = self.titleRect(forBounds: cellFrame) self.attributedStringValue.draw(in: titleRect) } }