How to center a subview of UIView

前端 未结 14 1961
無奈伤痛
無奈伤痛 2020-11-30 16:47

I have a UIView inside a UIViewm and I want the inner UIView to be always centered inside the outer one, without it having to resize t

14条回答
  •  情书的邮戳
    2020-11-30 17:28

    You can do this and it will always work:

    child.center = [parent convertPoint:parent.center fromView:parent.superview];
    

    And for Swift:

    child.center = parent.convert(parent.center, from:parent.superview)
    

提交回复
热议问题