How to fit different screens in iOS design-login interface

Source: Internet
Author: User
Tags uikit

In the iOS phone interface design, because of different phone types of mobile phone size is different, then in the design of the mobile phone interface to adapt to the screen, here to the landing interface design as a simple example of the implementation of the screen adaptation method: (Screen auto-fit zoom)

Effect:

The following is a look at the code implementation process:

1, the code implemented in the agent:

AppDelegate.h//Landing Interface Design#import<UIKit/UIKit.h>#definescreenheight [[UIScreen mainscreen]bounds].size.height//Screen Height#definescreenwidth [[UIScreen mainscreen]bounds].size.width//Screen Width@interfaceAppdelegate:uiresponder <UIApplicationDelegate>@property (Strong, nonatomic) UIWindow*window; @property (assign,nonatomic)floatAutosizescalex;//Zoom x@property (assign,nonatomic)floatAutosizescaley;//Zoom y@end
APPDELEGATE.M//Landing Interface Design#import "AppDelegate.h"@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {appdelegate*mydelegate=[[uiapplication Sharedapplication]Delegate]; if(screenheight>480) {//Zoom operation when screen height is greater than 4Smydelegate.autosizescalex=screenwidth/ the;//screen width zoom ratiomydelegate.autosizescaley=screenheight/480;//screen Height zoom ratio}Else{Mydelegate.autosizescalex=1.0; Mydelegate.autosizescaley=1.0; }        returnYES;}

2, the process of implementation in Viewcontroller

ViewController.h//Landing Interface Design#import<UIKit/UIKit.h>#import "AppDelegate.h"@interfaceViewcontroller:uiviewcontroller<uitextfielddelegate>@property (strong,nonatomic) Uitextfield*textnmae;//Edit text Box@property (strong,nonatomic) UIView *myview;//Edit Underline@property (strong,nonatomic) Uiimageview *imageview;//icons@property (strong,nonatomic) UIButton *mybutton;//control button@end
VIEWCONTROLLER.M//Landing Interface Design#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //Background MapSelf.imageview =[[uiimageview alloc]initwithimage:[uiimage imagenamed:@"Beijing.png"]]; //Icons 1[Self.view AddSubview:self.imageView]; Self.imageview=[[uiimageview Alloc]initwithframe:cgrectmake1 ( -, -, $, -)]; Self.imageView.image=[uiimage imagenamed:@"[email protected]"];        [Self.view AddSubview:self.imageView]; //Icons 2[Self.view AddSubview:self.imageView]; Self.imageview=[[uiimageview Alloc]initwithframe:cgrectmake1 ( -, -, -, -)]; Self.imageView.image=[uiimage imagenamed:@"[email protected]"];    [Self.view AddSubview:self.imageView]; //Icons 3[Self.view AddSubview:self.imageView]; Self.imageview=[[uiimageview Alloc]initwithframe:cgrectmake1 ( -, -, -, -)]; Self.imageView.image=[uiimage imagenamed:@"[email protected]"];    [Self.view AddSubview:self.imageView]; //Icons 4[Self.view AddSubview:self.imageView]; Self.imageview=[[uiimageview Alloc]initwithframe:cgrectmake1 ( -, -, -, -)]; Self.imageView.image=[uiimage imagenamed:@"[email protected]"];    [Self.view AddSubview:self.imageView]; //Underline 1Self.myview=[[uiview Alloc]initwithframe:cgrectmake1 ( -, -, -,1)]; Self.myView.backgroundColor=[Uicolor Whitecolor];    [Self.view AddSubview:self.myView]; //Underline 2Self.myview=[[uiview Alloc]initwithframe:cgrectmake1 ( -, the, -,1)]; Self.myView.backgroundColor=[Uicolor Whitecolor];       [Self.view AddSubview:self.myView]; //text Editing 1Self.textnmae=[[uitextfield Alloc]initwithframe:cgrectmake1 ( -, -, About, -)]; Self.textNmae.placeholder=@"Please enter your phone number"; Self.textNmae.font=[uifont systemfontofsize: -]; Self.textNmae.alpha=0.5; Self.textNmae.keyboardType= Uikeyboardtypenumberpad;//Keyboard TypeSelf.textnmae.clearbuttonmode=uitextfieldviewmodealways;//x Total Present[Self.view AddSubview:self.textNmae]; //Text Editing 2Self.textnmae=[[uitextfield Alloc]initwithframe:cgrectmake1 ( -, the, About, -)]; Self.textNmae.placeholder=@"Please enter your password"; Self.textNmae.secureTextEntry=yes;//Security PasswordSelf.textnmae.font=[uifont systemfontofsize: -]; Self.textNmae.alpha=0.5; Self.textnmae.Delegate=Self ; Self.textNmae.clearButtonMode=uitextfieldviewmodealways;//x Total Present[Self.view AddSubview:self.textNmae]; //Login ButtonSelf.mybutton=[[uibutton Alloc]initwithframe:cgrectmake1 ( -, $, -, -)]; [Self.mybutton settitle:@"Login"Forstate:uicontrolstatenormal];    [Self.mybutton Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal]; Self.myButton.backgroundColor=[uicolor colorwithred:arc4random ()% the/255.0Green:arc4random ()% the/255.0Blue:arc4random ()% the/255.0Alpha1.0]; [Self.myButton.layer Setcornerradius:Ten];//Rounded Corners[Self.view AddSubview:self.myButton]; //Register buttonSelf.mybutton=[[uibutton Alloc]initwithframe:cgrectmake1 ( -, the, -, -)]; [Self.mybutton settitle:@"Register"Forstate:uicontrolstatenormal];    [Self.mybutton Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal]; Self.myButton.backgroundColor=[uicolor colorwithred:arc4random ()% the/255.0Green:arc4random ()% the/255.0Blue:arc4random ()% the/255.0Alpha1.0]; [Self.myButton.layer Setcornerradius:Ten];//Rounded Corners[Self.view AddSubview:self.myButton]; }//Hide Keyboard-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{if([TextField Isfirstresponder]) {[TextField resignfirstresponder]; }    returnYES;}//Adaptive Scaling Methodcg_inline cgrect CGRectMake1 (cgfloat x, cgfloat y, cgfloat width, cgfloat height) {cgrect rect; Appdelegate*mydelegate=[[uiapplication Sharedapplication]Delegate]; Rect.origin.x=x*mydelegate.autosizescalex;//axis Scaling RECT.ORIGIN.Y=y*Mydelegate.autosizescaley; Rect.size.width=width*mydelegate.autosizescalex;//size Scaling rect.size.height=height*Mydelegate.autosizescaley; returnrect;}

How to fit different screens in iOS design-login interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.