Question

My StoryBoard is configured for iPhone4 resolution, and when running on iPhone 5 I'd like a UIView to get bigger (both height&width).

The problem right now is that the view is only getting higher and not wider. What should be the auto-resize configuration in order to achieve this?

enter image description here enter image description here

Was it helpful?

Solution

You will probably need to use a subclass of UIView with the setFrame: method overridden to catch frame changes.

- (void)setFrame:(CGRect)frame
{
    frame.size.width = frame.size.height; // Make the *width* always equal to the *height*. Logic could go here, etc.
    [super setFrame:frame]
}

OTHER TIPS

Reference the height of the screen and use some padding values to set your view frame. Below is code to set the frame of a UIView called yourShapeView:

// Get the frame of the screen
CGRect screenFrame = [[UIScreen mainScreen] bounds];

// Set padding from the top and bottom of the shape
CGFloat verticalPadding = 40.0f;
CGFloat horizontalPadding = 20.0f;

// Get the height/width values
CGFloat height = screenFrame.size.height - (verticalPadding * 2);
CGFloat width = screenFrame.size.width - (horizontalPadding * 2);

// Set the size of your shape based on the height and padding
yourShapeView.frame = CGRectMake(horizontalPadding, verticalPadding, width, height);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top