Screen fit and equal ratio scaling

Source: Internet
Author: User

#import <UIKit/UIKit.h>

#define WIDTH Self.view.frame.size.width

#define HEIGHT Self.view.frame.size.height

@interface viewcontroller:uiviewcontroller<uitextfielddelegate>

@property (strong,nonatomic) Uiimageview *imagev;

@property (strong,nonatomic) Uitextfield *txtid;

@property (strong,nonatomic) Uitextfield *txtmima;

@property (strong,nonatomic) UIButton *btnlogin;

@property (strong,nonatomic) UIButton *btnregister;

@property (strong,nonatomic) UILabel *label;

@property (strong,nonatomic) UIButton *btn1;

//

Viewcontroller.m

Screen fit

//

Created by TLH on 16/4/6.

COPYRIGHT©2016 year Lamco. All rights reserved.

//

#import "ViewController.h"

#import "UIViewExt.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.imagev=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, WIDTH, HEIGHT)];

Self.imagev.image=[uiimage imagenamed:@ "Beijing.png"];

[Self.view AddSubview:self.imageV];

Self.txtid=[[uitextfield Alloc]initwithframe:cgrectmake (self.view.left+90, Self.view.top +, WIDTH/2, HEIGHT/20)] ;

Self.txtid.backgroundcolor=[uicolor Whitecolor];

self.txtid.borderstyle=0;

[Email protected] "Please enter your account";

Set placeholder and its font color

self.txtid.delegate=self;

Uicolor *color1=[uicolor colorwithwhite:1.0 alpha:0.5];

self.txtid.attributedplaceholder=[[nsattributedstring alloc]initwithstring:@ "Please enter your account" attributes:@{ Nsforegroundcolorattributename:color1}];

Uiimageview *imagev=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "[email protected]"];

Self.txtid.clearbuttonmode=yes;

Self.txtid.leftview=imagev;

Self.txtid.leftviewmode=uitextfieldviewmodealways;

Self.label=[[uilabel Alloc]initwithframe:cgrectmake (self.view.left+90, Self.txtID.bottom, WIDTH/2, 1.0)];

Self.label.backgroundcolor=[uicolor Whitecolor];

[Self.view AddSubview:self.label];

[Self.view AddSubview:self.txtID];

Self.txtmima=[[uitextfield Alloc]initwithframe:cgrectmake (self.view.left+90, self.txtid.bottom+20, WIDTH/2, HEIGHT /20)];

[Email protected] "Please enter your password";

self.txtmima.delegate=self;

Uicolor *color=[uicolor colorwithwhite:1 alpha:0.5];

self.txtmima.attributedplaceholder=[[nsattributedstring alloc]initwithstring:@ "Please enter your password" attributes:@{ Nsforegroundcolorattributename:color}];

Self.txtmima.securetextentry=yes;

Uiimageview *imagev1=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "[email protected]"];

SELF.TXTMIMA.LEFTVIEW=IMAGEV1;

Self.txtmima.leftviewmode=uitextfieldviewmodealways;

UILabel *lbl=[[uilabel Alloc]initwithframe:cgrectmake (self.view.left+90, Self.txtmima.bottom, WIDTH/2, 1.0)];

Lbl.backgroundcolor=[uicolor Whitecolor];

[Self.view ADDSUBVIEW:LBL];

[Self.view AddSubview:self.txtmima];

Make password visible

Self.btn1=[uibutton Buttonwithtype:uibuttontyperoundedrect];

[Self.btn1 setbackgroundimage:[uiimage imagenamed:@ "[email protected]"] forstate:uicontrolstatenormal];

[Self. BTN1 addtarget:self action: @selector (display) forcontrolevents:uicontroleventtouchupinside];

Self.btn1.frame=cgrectmake (0, 0, SELF.TXTMIMA.WIDTH/12, self.txtmima.size.height);

SELF.TXTMIMA.RIGHTVIEW=SELF.BTN1;

Self.txtmima.rightviewmode= uitextfieldviewmodealways;

[Self.txtmima ADDSUBVIEW:SELF.BTN1];

Login button

Self.btnlogin=[uibutton Buttonwithtype:uibuttontyperoundedrect];

Self.btnlogin.frame=cgrectmake (self.view.left+90, self.txtmima.bottom+50, Width/2+imagev.size.width, HEIGHT/19);

[Self.btnlogin setbackgroundimage:[uiimage imagenamed:@ "[email protected]"] forstate:uicontrolstatenormal];

[Self.btnlogin settitle:@ "Landing" forstate:uicontrolstatenormal];

[Self.btnlogin Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];

[Self.view AddSubview:self.btnlogin];

Register button

Self.btnregister=[uibutton Buttonwithtype:uibuttontyperoundedrect];

Self.btnregister.frame=cgrectmake (self.view.left+90, self.btnlogin.bottom+20, Width/2+imagev.size.width, HEIGHT/ 19);

[Self.btnregister setbackgroundimage:[uiimage imagenamed:@ "[email protected]"] forstate:uicontrolstatenormal];

[Self.btnregister settitle:@ "registration" forstate:uicontrolstatenormal];

[Self.btnregister Settitlecolor:[uicolor Greencolor] forstate:uicontrolstatenormal];

[Self.view AddSubview:self.btnregister];

Welcome pictures

Uiimageview *imagev2=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "[email protected]"];

Imagev2.frame=cgrectmake (self.view.left+90, self.view.top+70, WIDTH/2, HEIGHT/19);

[Self.view Addsubview:imagev2];

Logo image

Uiimageview *imagev3=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "[email protected]"];

Imagev3.frame=cgrectmake (self.view.left+width/2-50, self.view.bottom-100, WIDTH/4, HEIGHT/18);

[Self.view Addsubview:imagev3];

Self.btnlogin=[uibutton Buttonwithtype:uibuttontyperoundedrect];

Self.btnlogin.frame=cgrectmake (self.view.left+50, self.txtmima.bottom+50, WIDTH/3, HEIGHT/7);

//

}

Keyboard

-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField

{

[Self.txtid Resignfirstresponder];

[Self.txtmima Resignfirstresponder];

return YES;

}

-(void) display

{

if (Self.txtmima.securetextentry==no) {

[Self.btn1 setbackgroundimage:[uiimage imagenamed:@ "[email protected]"] forstate:uicontrolstatenormal];

Self.txtmima.securetextentry=yes;

}

Else

{

[Self.btn1 setbackgroundimage:[uiimage imagenamed:@ "[email protected]"] forstate:uicontrolstatenormal];

Self.txtmima.securetextentry=no;

}

}

@property (strong,nonatomic) Uitextfield *txtname;

Viewcontroller.m

Equal ratio Scaling

//

Created by TLH on 16/4/6.

COPYRIGHT©2016 year Lamco. All rights reserved.

//

#import "ViewController.h"

#import "AppDelegate.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.txtname=[[uitextfield Alloc]initwithframe:cgrectmake1 (50, 100, 200, 55)];

Self.txtname.backgroundcolor=[uicolor Redcolor];

self.txtname.borderstyle=1;

[Self.view AddSubview:self.txtName];

}

Cg_inline CGRect

CGRectMake1 (cgfloat x,cgfloat y,cgfloat width,cgfloat height)

{

CGRect rect;

Appdelegate *mydelegate=[[uiapplication Sharedapplication] delegate];

Rect.origin.x=x * MYDELEGATE.AUTOSIZESCALEX;

Rect.origin.y=y * Mydelegate.autosizescaley;

Rect.size.width=width *mydelegate.autosizescalex;

Rect.size.height=height *mydelegate.autosizescaley;

return rect;

}

Screen fit and equal ratio scaling

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.