I have a small problem with NSTableView. When I am increasing height of a row in table, the text in it is aligned at top of row but I want to align it vertically centered!
Can anyone suggest me any way to do it ??
Thanks,
Miraaj
I have a small problem with NSTableView. When I am increasing height of a row in table, the text in it is aligned at top of row but I want to align it vertically centered!
Can anyone suggest me any way to do it ??
Thanks,
Miraaj
@iphaaw's answer updated for Swift 4 (note I also added "Cell" on the end of the class name for clarity, which also needs to match the class name in Interface Builder):
This is a simple code solution that shows a subclass you can use to middle align a TextFieldCell.
the header
the code
This blog entry shows an alternative solution that also works well.
Even if this is a very old question with an accepted answer, here's an alternate solution:
Go into the IB, select your NSTextField sitting in a NSTableCellView and add a new "Center Vertically in Container" constraint. You should also add horizontal constraints (which should probably be leading/trailing space set to 0 or whatever suits your needs).
Used this in an NSOutlineView and worked like a charm. Performance wasn't an issue in my case, as I didn't have many cells, but I would expect it's not worse than manually calculating sizes.
Here is the Swift version of the code building on the answer above:
Then I set the height of the tableView heightOfRow in the NSTableView:
Set the class of the NSTextFieldCell to be VerticallyCenteredTextField:
and the height of the TableViewCell
Thanks Bryan for your help.