Reputation: 68750
I have a small UIImageView
and wish to centre it horizontally inside a UIView
which is as wide as the screen.
I also wish to have the UIImageView stay centered when the device rotates.
How is this done?
Upvotes: 1
Views: 4200
Reputation: 21967
This will center imageView
horizontally within view
:
imageView.frame.origin.x = CGRectGetMidX(view.bounds) - CGRectGetMidX(imageView.bounds)
This will ensure that imageView
stays horizontally centered when its superview's bounds change:
imageView.autoresizingMask = UIViewAutoResizingFlexibleLeftMargin|UIViewAutoResizingFlexibleRightMargin
Upvotes: 3