xonegirlz xonegirlz - 5 months ago 18
Objective-C Question

How to center a subview of UIView

I have a

UIView
inside a
UIView
m and I want the inner
UIView
to be always centered inside the outer one, without it having to resize the width and height.

I've set the struts and springs so that it's on top/left/right/bottom without setting the resize. But it still doesn't center. Any idea?

Answer

Try:

yourSubView.center = CGPointMake(yourView.frame.size.width  / 2, 
                                 yourView.frame.size.height / 2);