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)?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With