Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to call initWithFrame on a UIView class or subclass with CGRectZero?

Tags:

uikit

iphone

I have seen code that calls initWithFrame of a UIView subclass (such as UILabel) with CGRectZero and things seem to work fine. What does it mean to instantiate a UIView subclass with a 2D point (which seems to be what CGRectZero is)?

like image 404
Boon Avatar asked Dec 23 '22 11:12

Boon


1 Answers

It just means that you're instantiating the view without an initial value for its frame.

This is done, for instance, when you want to create an instance of the view object and do not need to place it into the view hierarchy right away. Deciding upon and setting the frame can be performed at a later time, using setFrame:.

CGRectZero is commonly used when initializing UITableViewCell's, in SDK 2.x that is. An instance of the view is needed in tableView:cellForRowAtIndexPath:, and there's no need to supply the frame upon creation because the table view will automatically position the cell and makes it the optimal size at a later time.

like image 133
Sean Patrick Murphy Avatar answered May 13 '23 09:05

Sean Patrick Murphy