As the popularity of iPhone 5 increases, we have to 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:
- [cpp]
-
- self.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin
-
- | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin
-
- | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
-
- self.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin
-
- | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin
-
- | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
Next, set the sub-view, such as button and image ):
Code:
- [cpp]
-
- autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
-
- .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:
- [Cpp]
-
- # Define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds]. size. height = 568)
-
- # Define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds]. size. height = 568). Then we can change the frame during view initialization:
-
- [Cpp]
-
- If (DEVICE_IS_IPHONE5 ){
-
- [Botton setFrame: CGRectMake (0,450,320,440)];
-
- }
-
- If (DEVICE_IS_IPHONE5 ){
-
- [Botton setFrame: CGRectMake (0,450,320,440)];