Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to determine UITableViewCell width for grouped custom cells?

I have a custom UITableViewCell created through code (not Interface Builder). I have sub-views that rely on the width of the cell: there is a label that always needs to be just inside the right edge of the cell. The cells appear in a grouped table view.

I had originally hard-coded the values to work with iPhone, but now I'm converting the app to a universal binary and the hard-coded numbers are out for grouped table views on the iPad.

Is there a proper way to get the width of the cell? The frame returns the full screen width, which is throwing my labels out of place. Or should I just hard-code two sets of values, one for iPhone and one for iPad?

Any suggestions would be greatly appreciated.

like image 361
SeanR Avatar asked Jan 20 '23 07:01

SeanR


1 Answers

You should be able to get the appropriate dimensions from the cell's contentView subview. But you should normally just set the sizes and autoresizing masks on your subviews so that the cell will appear correctly no matter what the specific width ends up being.

like image 100
Anomie Avatar answered Jan 31 '23 07:01

Anomie