¿Qué significa esto? initWithFrame: CGRectZero]

I created switch in cellForRowAtIndexPath like this.

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

CGRectZero is equivalent to CGRectMake(0,0,0,0). But, switch is seen in normal size. I didn't specified actuall size. Please explain to me how above code works.

preguntado el 27 de agosto de 11 a las 15:08

2 Respuestas

UISwitch is not customizable, this also applies to the size.

UISwitch overrides initWithFrame: and enforces a size appropriate for the control. The size components of the given rectangle are ignored.

Respondido 27 ago 11, 19:08

actually UISwitch overrides sizeThatFits: but the effect is the same. - progrmr

Any UIView object can override the frame size by implementing the sizeThatFits: method of UIView. In fact the Referencia de la clase UIView dice que:

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

Respondido 27 ago 11, 21:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.