When the iPhone 5 comes out, we will adapt to screens with different resolutions like android.
The new version of the company's products must be adapted to the iPhone 5. After some effort, it is done. I would like to share with you the following:
IPhone 5 screen resolution: 1136x640, that is, when the height changes to 568, the name of the image is default-568h@2x.png. When we create a project, xcode creates a pure black image by default.
The latest version of xcode supports debugging for iPhone 5: select the simulator ----> device ----> iPhone (retina 4-inch). You can switch to the iPhone 5 simulator in a moment.
To adapt to iPhone 5, you must set the autosizing of the view to the following status:
Of course, make sure to select another item.
This option is selected by default, which means the subview is automatically scaled.
If our view does not use XIB, we can use the code to set these attributes:
self.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
Next, set the sub-view (such as button and image ):
Code:
.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
This means that when the control is scaled, it corresponds to the left and top of the parent view. You can set the autorizingmask value for the Child control as needed.
You can also use the code to manually change the size or location of the control in iPhone 5:
First determine whether the device is iphone5:
#define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568)
Then, we can change the frame when the view is initialized:
if (DEVICE_IS_IPHONE5) { [botton setFrame:CGRectMake(0, 450, 320, 440)];}
Through the above work, we can perfectly adapt to the iPhone 5.
Haha, That's easy!
Please leave a message if you have any questions!
Note: Please indicate the source for reprinting!