#import <UIKit/UIKit.h>ide
#define WIDTH self.view.frame.size.width字體
#define HEIGHT self.view.frame.size.heightatom
@interface ViewController : UIViewController<UITextFieldDelegate>orm
@property(strong,nonatomic)UIImageView *imageV;圖片
@property(strong,nonatomic)UITextField *txtID;get
@property(strong,nonatomic)UITextField *txtmima;it
@property(strong,nonatomic)UIButton *btnlogin;io
@property(strong,nonatomic)UIButton *btnregister;import
@property(strong,nonatomic)UILabel *label;select
@property(strong,nonatomic)UIButton *btn1;
//
// ViewController.m
// 屏幕適配
//
// Created by tlh on 16/4/6.
// Copyright © 2016年 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 + 150, WIDTH/2, HEIGHT/20)];
// self.txtID.backgroundColor=[UIColor whiteColor];
// self.txtID.borderStyle=0;
// self.txtID.placeholder=@" 請輸入帳號" ;
// 設置佔位符及其字體顏色
self.txtID.delegate=self;
UIColor *color1=[UIColor colorWithWhite:1.0 alpha:0.5];
self.txtID.attributedPlaceholder=[[NSAttributedString alloc]initWithString:@"請輸入帳號" attributes:@{NSForegroundColorAttributeName:color1}];
UIImageView *imagev=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"phoneIcon@x.png"]];
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)];
// self.txtmima.placeholder=@" 請輸入密碼";
self.txtmima.delegate=self;
UIColor *color=[UIColor colorWithWhite:1 alpha:0.5];
self.txtmima.attributedPlaceholder=[[NSAttributedString alloc]initWithString:@"請輸入密碼" attributes:@{NSForegroundColorAttributeName:color}];
self.txtmima.secureTextEntry=YES;
UIImageView *imagev1=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"passwordIcon@x.png"]];
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];
// 使密碼可見
self.btn1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.btn1 setBackgroundImage:[UIImage imageNamed:@"btn_password_hidden@3x.png"] 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];
// 登錄按鈕
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:@"loginButton@x.png"] forState:UIControlStateNormal];
[self.btnlogin setTitle:@"登錄" forState:UIControlStateNormal];
[self.btnlogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.view addSubview:self.btnlogin];
// 註冊按鈕
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:@"rigisterButton@2x.png"] forState:UIControlStateNormal];
[self.btnregister setTitle:@"註冊" forState:UIControlStateNormal];
[self.btnregister setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[self.view addSubview:self.btnregister];
// welcome 圖片
UIImageView *imagev2=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"welcome@2.png"]];
imagev2.frame=CGRectMake(self.view.left+90, self.view.top+70, WIDTH/2, HEIGHT/19);
[self.view addSubview:imagev2];
// logo圖片
UIImageView *imagev3=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"logo@2x.png"]];
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);
//
}
//鍵盤
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.txtID resignFirstResponder];
[self.txtmima resignFirstResponder];
return YES;
}
-(void)display
{
if (self.txtmima.secureTextEntry==NO) {
[self.btn1 setBackgroundImage:[UIImage imageNamed:@"btn_password_hidden@3x.png"] forState:UIControlStateNormal];
self.txtmima.secureTextEntry=YES;
}
else
{
[self.btn1 setBackgroundImage:[UIImage imageNamed:@"btn_password_show@2x.png" ] forState:UIControlStateNormal];
self.txtmima.secureTextEntry=NO;
}
}
@property(strong,nonatomic)UITextField *txtName;
// ViewController.m
// 等比縮放
//
// Created by tlh on 16/4/6.
// Copyright © 2016年 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;
}