Search code examples
iosios6

how to align subviews to the center of parent view?


I create a CenterContainerView, which contains imageViews, after I add an imageView to CenterContainerView, the subviews of CenterContainerView are automatically aligned to center, I don't know how to implement it, I think may be I should use autoresizing mask to do it, right?


Solution

  • To align subviews to the center of superView use the center property of a view.

    imageView.center = CenterContainerView.center;