ecco la versione Swift dell'edificio codice a risposta di cui sopra:
import Foundation
import Cocoa
class VerticallyCenteredTextField : NSTextFieldCell
{
override func titleRectForBounds(theRect: NSRect) -> NSRect
{
var titleFrame = super.titleRectForBounds(theRect)
var titleSize = self.attributedStringValue.size
titleFrame.origin.y = theRect.origin.y - 1.0 + (theRect.size.height - titleSize.height)/2.0
return titleFrame
}
override func drawInteriorWithFrame(cellFrame: NSRect, inView controlView: NSView)
{
var titleRect = self.titleRectForBounds(cellFrame)
self.attributedStringValue.drawInRect(titleRect)
}
}
Poi ho impostato l'altezza della tableView heightOfRow nella NSTableView:
func tableView(tableView: NSTableView, heightOfRow row: Int) -> CGFloat
{
return 30
}
impostare la classe del NSTextFieldCell da VerticallyCenteredTextField:

e l'altezza del TableViewCell


Grazie Bryan per il vostro aiuto.
'dimensioni 'assume una larghezza infinita - non tiene conto del ritorno a capo. Suggerisco 'boundingRectForSize: options:', con la dimensione da 'cellFrame', invece. –