Vishal Singh
Vishal Singh

Reputation: 4480

Proper AutoresizingMask

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;

Upvotes: 16

Views: 14359

Answers (3)

Vladimir Zivanov
Vladimir Zivanov

Reputation: 380

Swift 3:

childView.translatesAutoresizingMaskIntoConstraints = false

childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin]

Upvotes: 3

Lombas
Lombas

Reputation: 1132

If you are using swift:
// horizontal
childView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin]
// vertical
childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin]
// both
childView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin]

Upvotes: 0

Christian Schnorr
Christian Schnorr

Reputation: 10776

// horizontal
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

// vertical
childView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

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

Upvotes: 29

Related Questions