Question

I was wondering if there was any way to automatically and programmatically generate frames for different size screens like they are done in storyboard. In storyboard, as long as the autosizing mask is set correctly, the frames for the views are generated dynamically to fill the entire screen. This can be shown when the 'Apply Alternate Device Form Factor' button in storyboard is pressed and the screen size & content grow or shrink dynamically. However, whenever I try to get this same behavior while creating views programmatically, the frame does not scale dynamically. Is there any way to generate this frame automatically like Storyboard based on the current devices framework? Is there any elegant solution to programmatically create views for different size devices without needing to manually manage static frames for each devices? Does anyone have any resources they could share or examples that they could provide?

Thanks. I appreciate the assistance.

Was it helpful?

Solution

Instead of setting the frame statically you should place the frame based on the size (height for example) from areas. For instance this would create the view and place it 50 from the bottom and also stretch the size if the devices height was 568 instead of 480).

someView.frame = CGRectMake (0,someView.frame.size.height + (self.view.frame.size.height - 50),100 + (480 - self.view.frame.height),100);

OTHER TIPS

If you're targeting iOS6 you can use Auto Layout. If you're not targeting iOS6 (or you don't want to mess with Auto Layout) you can set UIView's autoResizingMask property to whatever you want. i.e. view.autoResizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top