gabitzish
gabitzish

Reputation: 9691

Fixed size UIView, centered in the view

I want to have an UIView with width=480 and height=640, centered in the middle of my master view.

I want this to happen both in landscape orientation and portrait orientation, but now if I design it for portrait orientation, when I'm turning the device to landscape, my UIView has width=640 and height=480.

Any solutions for my UIView to keep it's sizes in both orientation types?

Upvotes: 2

Views: 509

Answers (1)

Bryan Chen
Bryan Chen

Reputation: 46608

you can implement viewDidLayoutSubviews (in UIViewController) or layoutSubviews (in UIView) to reposition the view.

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.myCustomView.bounds = CGRectMake(0, 0, 480, 640); // update size
    self.myCustomView.center = self.view.center;           // update center
}

Upvotes: 3

Related Questions