What does it mean? initWithFrame: CGRectZero]

I created a switch in cellForRowAtIndexPath like this.

UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero]; 

CGRectZero is equivalent to CGRectMake (0,0,0,0). But the switch is displayed in normal size. I did not indicate the actual size. Please explain to me how the code works.

+7
source share
2 answers

UISwitch is not configurable, this also applies to size.

UISwitch overrides initWithFrame: and sets the size to fit the control. The size components of this rectangle are ignored.

+6
source

Any UIView object can override the frame size by implementing the sizeThatFits: UIView method. In fact, the UIView link says that:

the UISwitch object returns a fixed size value that represents the standard size of the switch view

0
source

All Articles