How to center a subview of UIView

前端 未结 14 1931
無奈伤痛
無奈伤痛 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:35

    You can use

    yourView.center = CGPointMake(CGRectGetMidX(superview.bounds), CGRectGetMidY(superview.bounds))
    

    And In Swift 3.0

    yourView.center = CGPoint(x: superview.bounds.midX, y: superview.bounds.midY)
    

提交回复
热议问题