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

I saw code that calls the initWithFrame a UIView subclass (like UILabel ) using CGRectZero , and everything looks fine. What does it mean to instantiate a UIView subclass with a two-dimensional point (which, apparently, is what CGRectZero )?

+4
source share
1 answer

It just means that you are creating a view with no initial value for its frame.

This is done, for example, when you want to instantiate a view object and do not immediately insert it into the view hierarchy. The solution and setting the frame can be done later using setFrame :.

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

+11
source

All Articles