PDA

View Full Version : Centering text in column's of table view




satyam90
Oct 3, 2008, 02:59 AM
I am using ObjC with cocoa framework.
I have a table view with 4 columns. From IB I am able to center the text in columns horizontally. But how to centre the text "Vertically"



HiRez
Oct 3, 2008, 03:32 AM
As far as I know, there's no way to set vertical cell contents alignment either in IB or programmatically, and there sure should be. I think two choices you might look at are using NSAttributedStrings for your cells and adjusting the baseline, or subclassing NSCell to override its drawInteriorWithFrame:inView: method. Either way you'll have to calculate the offset based on the text rectangle and the cell frame.

satyam90
Oct 3, 2008, 04:56 AM
I have NSArrayController with data (strings, date, image etc) available in it and I am binding my table columns to it. So neither I am using seperate NSCell nor I am using NSAttributedStrings...............

kainjow
Oct 3, 2008, 03:26 PM
Is this (http://www.red-sweater.com/blog/148/what-a-difference-a-cell-makes) what you want?