Aquí está la versión Swift del edificio código en la respuesta anterior:
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)
}
}
Entonces fijar la altura de la tableView heightOfRow en el NSTableView:
func tableView(tableView: NSTableView, heightOfRow row: Int) -> CGFloat
{
return 30
}
definen la clase de la NSTextFieldCell que se VerticallyCenteredTextField:
y la altura de la TableViewCell
Gracias Bryan por su ayuda.
'tamaño 'supone un ancho infinito; no tiene en cuenta el ajuste de línea. Sugiero 'boundingRectForSize: options:', con el tamaño de 'cellFrame', en su lugar. –