Question

I have a view that appears at the center of its parent view portrait mode, what autoresizemask should I use so that it appears in the center in landscape mode too. It's size should remain same.I just want its origin should shift themselves automatically at the point so that it appears at the center.Any help please?

I have given

[parentView setAutoResizesSubview:YES];

parentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
Was it helpful?

Solution

// horizontal
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

// vertical
childView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

// both
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

OTHER TIPS

Swift 3:

childView.translatesAutoresizingMaskIntoConstraints = false

childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin]
If you are using swift:
// horizontal
childView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin]
// vertical
childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin]
// both
childView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top