iOS Question Get an UIview height (or convert from Objective C)


Well-Known Member
Licensed User
Hi, i made a post before about the centering of a switch.
i noticed that the switch is positioned in the top left corner of his hitbox.
I need to center it.

So the only way, i think, is to make the hitbox height (and width) equal to the effective height (and width) of the ios switch.

There is a way to retrive this information from the native language?

i found this on internet but i don't know Objective C, and i don't know if this is useful

CGFloat selfHeight=self.view.bounds.size.height;
CGFloat selfWidth=self.view.bounds.size.width;
CGFloat boxHeight=box.bounds.size.height;
CGFloat boxWidth=box.bounds.size.width;
from here:



Well-Known Member
Licensed User
I think that you are working too hard for something very simple. Measure the switch size. It doesn't change between different devices (at least not significantly).
The size is 51 * 31.

This is something specific to the switch view, as most other views do resize based frame size.
This is what I‘ve done.
I was not sure about the reliability of this method between different devices 😕
thanks Erel


Well-Known Member
Licensed User
Ok if i disable the "Manage resize event" check in the designer, this code work.. but at this point i've to code manually all the design contraints in the page code D:

until this moment i did all only with anchors points.. disabling that check all the panels etc.. collapse, even if the anchors are set to be "left and right"