登陆界面(LTView,UITextField,UIButton)

设置几个类

AppDelegate

LTView

RootViewController

LoginViewController

RegistViewController

PasswordViewController

AppDelegate.m

application中
// 设置一个UIViewController
RootViewController *rootVC=[[RootViewController alloc]init];
// 设置window根视图控制器
self.window.rootViewController=rootVC;
[rootVC release];

LTView.h

@interface LTView : UIView<UITextFieldDelegate>
@property(nonatomic,retain)UILabel *label;
@property(nonatomic,retain)UITextField *textField;
@property(nonatomic,retain)UIButton *button;
@end

LTView.m

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];// 这个事情UIView还会做,LTView继承与UIView
    if (self) {
        // 在代码区写额外的事就可以了
        // 模块化
        // 自己调用自己的方法
        [self createView];
    }
    return self;
}

// 创建无返回值无参数的视图方法
-(void)createView
{
    // label
    self.label=[[UILabel alloc]initWithFrame:CGRectMake(50, 0, 100, 30)];
    [self addSubview:self.label];
    [self.label release];

    // textField
    self.textField=[[UITextField alloc]initWithFrame:CGRectMake(170, 0, 150, 30)];
    [self addSubview:self.textField];
    self.textField.layer.borderWidth=1;
    self.textField.layer.cornerRadius=10;
    self.textField.clearButtonMode=UITextFieldViewModeAlways;
//    self.textField.alpha=0.3;
    self.textField.tag=1;
    self.textField.layer.masksToBounds=YES;
    self.textField.delegate=self;
    [self.textField release];
}

// 回收键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return self;
}

// 释放   记得
-(void)dealloc
{
    [_textField release];
    [_label release];
    [super dealloc];
}

RootViewController.h

@interface RootViewController : UIViewController
@property(nonatomic,retain)UILabel *label;
@property(nonatomic,retain)UITextField *textField;
@end

RootViewController.m

#import "RootViewController.h"
#import "LoginViewController.h"
#import "RegistViewController.h"
#import "PasswordViewController.h"
#import "LTView.h"

@interface RootViewController ()<UITextFieldDelegate,UIAlertViewDelegate>

@property(nonatomic,retain)UIAlertView *alertview;

@property(nonatomic,assign)BOOL isChecked;

@end

@implementation RootViewController
-(void)dealloc
{
    [_alertview release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    UIColor *bgColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"3.jpg"]];
    [self.view setBackgroundColor:bgColor];
    // 设置账户密码label和textField
    LTView *view1=[[LTView alloc]init];
    view1.frame=CGRectMake(0, 100, 375, 30);
    [self.view addSubview:view1];
    view1.label.text[email protected]"账户名";
    view1.textField.clearButtonMode=UITextFieldViewModeAlways;
    view1.textField.placeholder[email protected]"请输入账户名";
    view1.textField.returnKeyType = UIReturnKeyDefault;
    view1.textField.tag=1;
    [view1 release];

    LTView *view2=[[LTView alloc]initWithFrame:CGRectMake(0, 150, 375, 30)];
    [self.view addSubview:view2];
    view2.label.text[email protected]"密码";
    view2.textField.clearButtonMode=UITextFieldViewModeAlways;
    view2.textField.placeholder[email protected]"请输入密码";
    view2.textField.returnKeyType = UIReturnKeyDone;
    view2.textField.secureTextEntry=YES;
//    view2.textField.delegate = self;
    view2.textField.tag=2;
    [view2 release];

    // 设置登陆button
    UIButton *loginButton=[UIButton buttonWithType:UIButtonTypeSystem];
    loginButton.frame=CGRectMake(60, 250, 60, 30);
    [loginButton setTitle:@"登陆" forState:UIControlStateNormal];
    [self.view addSubview:loginButton];
    [loginButton addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];
    // 设置找回密码button
    UIButton *passwordButton=[UIButton buttonWithType:UIButtonTypeSystem];
    passwordButton.frame=CGRectMake(150, 250, 60, 30);
    [passwordButton setTitle:@"找回密码" forState:UIControlStateNormal];
    [self.view addSubview:passwordButton];
    [passwordButton addTarget:self action:@selector(click2:) forControlEvents:UIControlEventTouchUpInside];
    // 设置注册button
    UIButton *registButton=[UIButton buttonWithType:UIButtonTypeSystem];
    registButton.frame=CGRectMake(240, 250, 60, 30);
    [registButton setTitle:@"注册" forState:UIControlStateNormal];
    [self.view addSubview:registButton];
    [registButton addTarget:self action:@selector(click3:) forControlEvents:UIControlEventTouchUpInside];

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(50, 200, 50, 20)];
    [self.view addSubview:label];
    label.text[email protected]"显示密码";
    [label sizeToFit];
    [label release];

    // button
    UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
    button.frame=CGRectMake(150, 200, 50, 20);
    [self.view addSubview:button];
    [button setBackgroundImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];
    [button sizeToFit];
    [button addTarget:self action:@selector(click4:) forControlEvents:UIControlEventTouchUpInside];

    self.isChecked=YES;
}

// 回收键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

// 登陆button的click方法
-(void)click1:(UIButton *)button
{
    UITextField *accountTextfield=(UITextField *)[self.view viewWithTag:1];
    UITextField *passwordTextField=(UITextField *)[self.view viewWithTag:2];

    if ([accountTextfield.text isEqualToString:@"123"]&&[passwordTextField.text isEqualToString:@"333"]) {
        // 创建一个secondVC的对象
        LoginViewController *loginVC=[[LoginViewController alloc]init];
        // 设置一下跳转时候的动画效果
        [loginVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
        // 进行跳转
        [self presentViewController:loginVC animated:YES completion:^{
        }];
        // 内存管理
        [loginVC release];
    }
    else{
        self.alertview=[[UIAlertView alloc]initWithTitle:@"警告" message:@"账号 密码输入错误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
        [self.alertview show];
    }
}

// 找回密码button的click方法
-(void)click2:(UIButton *)button
{
    // 创建一个secondVC的对象
    PasswordViewController *passwordVC=[[PasswordViewController alloc]init];
    // 设置跳转时候的动画效果
    [passwordVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        // 进行跳转
    [self presentViewController:passwordVC animated:YES completion:^{
    }];
    // 内存管理
    [passwordVC release];
}

// 注册button的click方法
-(void)click3:(UIButton *)button
{
    // 创建一个secondVC的对象
    RegistViewController *registVC=[[RegistViewController alloc]init];
    // 设置跳转时候的动画效果
    [registVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    // 进行跳转
    [self presentViewController:registVC animated:YES completion:^{
  }];
    // 内存管理
    [registVC release];
}

// 显示密码的button方法
-(void)click4:(UIButton *)button
{
    UITextField *textField=(UITextField *)[self.view viewWithTag:2];
    if (self.isChecked) {
        [button setBackgroundImage:[UIImage imageNamed:@"BtnOn.png"] forState:UIControlStateNormal];
        [button sizeToFit];
        textField.secureTextEntry=NO;
    }else{
        [button setBackgroundImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];
        textField.secureTextEntry=YES;
    }
    self.isChecked=!self.isChecked;
}

界面如下
![这里写图片描述](http://img.blog.csdn.net/20150806211201408)

LoginViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIColor *bgColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"2.png"]];
    [self.view setBackgroundColor:bgColor];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame=CGRectMake(100, 100, 200, 30);
    button.layer.borderWidth=1;
    button.layer.cornerRadius=10;
    [self.view addSubview:button];
    [button setTitle:@"登陆成功  返回上一界面" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)click:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

![这里写图片描述](http://img.blog.csdn.net/20150806211353921)

![这里写图片描述](http://img.blog.csdn.net/20150806211449970)

RegistViewController.m

#import "RegistViewController.h"
#import "LTView.h"
#define HEIGHT self.view.frame.size.height
@interface RegistViewController ()<UITextFieldDelegate>

@property(nonatomic,assign)BOOL isChecked;

@end

@implementation RegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    UIColor *bgColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"7.jpg"]];
    [self.view setBackgroundColor:bgColor];

    LTView *view1=[[LTView alloc]init];
    view1.frame=CGRectMake(0, 100, 375, 30);
    [self.view addSubview:view1];
    view1.label.text[email protected]"账户名";
    view1.textField.clearButtonMode=YES;
    view1.textField.placeholder[email protected]"请输入账户名";
    view1.textField.returnKeyType = UIReturnKeyNext;
    view1.textField.tag=1;
    [view1.textField addTarget:self action:@selector(nameTextField_DidEndOnExit:) forControlEvents:UIControlEventTouchUpInside];
    [view1 release];

    LTView *view2=[[LTView alloc]initWithFrame:CGRectMake(0, 150, 375, 30)];
    [self.view addSubview:view2];
    view2.label.text[email protected]"密码";
    view2.textField.clearButtonMode=UITextFieldViewModeAlways;
    view2.textField.placeholder[email protected]"请输入账户名";
    view2.textField.secureTextEntry=YES;
    view2.textField.tag=2;
    [view2 release];

    LTView *view3=[[LTView alloc]init];
    view3.frame=CGRectMake(0, 200, 375, 30);
    [self.view addSubview:view3];
    view3.label.text[email protected]"确认密码";
    view3.textField.clearButtonMode=UITextFieldViewModeAlways;
    view3.textField.placeholder[email protected]"请输入密码";
    view3.textField.secureTextEntry=YES;
    view3.textField.tag=3;
    [view3 release];

    LTView *view4=[[LTView alloc]init];
    view4.frame=CGRectMake(0, 250, 375, 30);
    [self.view addSubview:view4];
    view4.label.text[email protected]"手机号";
    view4.textField.clearButtonMode=UITextFieldViewModeAlways;
    view4.textField.placeholder[email protected]"请输入手机号";
    view4.textField.keyboardType = UIKeyboardTypeNumberPad;
    view4.textField.tag=4;
    [view4 release];

    LTView *view5=[[LTView alloc]init];
    view5.frame=CGRectMake(0, 300, 375, 30);
    [self.view addSubview:view5];
    view5.label.text[email protected]"邮箱";
    view5.textField.clearButtonMode=UITextFieldViewModeAlways;
    view5.textField.placeholder[email protected]"请输入邮箱地址";
    view5.textField.returnKeyType = UIReturnKeyDone;
    view5.textField.keyboardType = UIKeyboardTypeEmailAddress;
    view5.textField.delegate=self;
    view5.textField.tag=5;
    [view5 release];

    // 设置注册和取消button
    UIButton *registButton=[UIButton buttonWithType:UIButtonTypeSystem];
    registButton.frame=CGRectMake(90, 420, 60, 30);
    [registButton setTitle:@"注册" forState:UIControlStateNormal];
    [self.view addSubview:registButton];

    UIButton *QXButton=[UIButton buttonWithType:UIButtonTypeSystem];
    QXButton.frame=CGRectMake(200, 420, 60, 30);
    [QXButton setTitle:@"取消" forState:UIControlStateNormal];
    [self.view addSubview:QXButton];
    [QXButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(50, 350, 50, 20)];
    [self.view addSubview:label];
    label.text[email protected]"显示密码";
    [label sizeToFit];
    [label release];

    // button
    UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
    button.frame=CGRectMake(150, 350, 50, 20);
    [self.view addSubview:button];
    [button setBackgroundImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];
    [button sizeToFit];
    [button addTarget:self action:@selector(click4:) forControlEvents:UIControlEventTouchUpInside];

    self.isChecked=YES;
}

// 显示密码的button方法
-(void)click4:(UIButton *)button
{
    UITextField *textField1=(UITextField *)[self.view viewWithTag:3];
    UITextField *textField2=(UITextField *)[self.view viewWithTag:4];
    if (self.isChecked) {
        [button setBackgroundImage:[UIImage imageNamed:@"BtnOn.png"] forState:UIControlStateNormal];
        [button sizeToFit];
        textField1.secureTextEntry=NO;
        textField2.secureTextEntry=NO;
    }else{
        [button setBackgroundImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];
        textField1.secureTextEntry=YES;
        textField2.secureTextEntry=YES;
    }
    self.isChecked=!self.isChecked;
}

// 使view往上走
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField.frame.origin.y > HEIGHT /2) {
        CGFloat height=textField.frame.origin.y - HEIGHT/2;
        self.view.center=CGPointMake(self.view.center.x, self.view.center.y - height);
    }
    return YES;
}

// 等到编译结束的时候,再让他回到原位
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    if (textField.frame.origin.y > HEIGHT / 2) {
        CGFloat height = textField.frame.origin.y - HEIGHT / 2;
        self.view.center = CGPointMake(self.view.center.x, self.view.center.y + height);
    }
    return YES;
}

// 取消的点击方法
-(void)click:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

![这里写图片描述](http://img.blog.csdn.net/20150806211552272)

PasswordViewController.m

#import "PasswordViewController.h"

@interface PasswordViewController ()<UITextFieldDelegate>

@end

@implementation PasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIColor *bgColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"aa18972bd40735fa735032ab9a510fb30f24087b.jpg"]];
    [self.view setBackgroundColor:bgColor];
    // 设置一个textfield
    UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(80, 100, 200, 30)];
    [self.view addSubview:textField];
    textField.layer.borderWidth=1;
    textField.layer.cornerRadius=10;
    textField.placeholder[email protected]"请输入邮箱";
    textField.keyboardType=UIKeyboardTypeEmailAddress;
    textField.returnKeyType = UIReturnKeyDone;
    textField.alpha=0.3;
    textField.delegate=self;
    [textField release];

    //设置两个button
    UIButton *button1=[UIButton buttonWithType:UIButtonTypeSystem];
    button1.frame=CGRectMake(90, 170, 70, 30);
    [self.view addSubview:button1];
    [button1 setTitle:@"找回" forState:UIControlStateNormal];

    UIButton *button2=[UIButton buttonWithType:UIButtonTypeSystem];
    button2.frame=CGRectMake(200, 170, 70, 30);
    [self.view addSubview:button2];
    [button2 setTitle:@"取消" forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}

// 点击return回收键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
-(void)click:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

![这里写图片描述](http://img.blog.csdn.net/20150806211638858)

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-18 12:44:36

登陆界面(LTView,UITextField,UIButton)的相关文章

iOS设计中不同屏幕适配的方法-登陆界面

在iOS的手机界面设计中,由于不同手机类型的手机的尺寸不同,那么在设计手机界面时就得对屏幕进行适配,这里就以登陆界面的设计为例简单说明下 实现屏幕适配的方法:(屏幕自动适配缩放) 效果: 下面就看下代码实现的过程: 1.在代理中实现的代码: AppDelegate.h // 登陆界面设计 #import <UIKit/UIKit.h> #define ScreenHeight [[UIScreen mainScreen]bounds].size.height//屏幕高度 #define Scr

[iOS基础控件 - 3.1] QQ登陆界面

A.storyboard 控件版 1.label 2.textfield a.Keyboard Type 账号:Number Pad 密码:Number and Punctuation b.Placeholder:提示文字 c.Clear Button: Appears with editing 清除按钮 d.Secure Text Entry:密码格式输入 3.button 1 @interface ViewController () 2 @property (weak, nonatomic)

ios模仿qq登陆界面

给大家推荐两个学习的地址: 极客学院的视频:http://www.jikexueyuan.com/path/ios/ 一个博客:http://blog.csdn.net/lizhongfu2013/article/details/29210015 主要想要实现一个模仿的登陆界面 代码: // // LoginViewController.swift // IBM_LOGIN // // Created by dcintern on 6/26/15. // Copyright (c) 2015 d

iOS开发从入门到精通--XIB使用,登陆界面小试牛刀

XIB使用,登陆界面小试牛刀 创建一个新的视图控制器,具体操作参见点击查看 在创建好的VCRoot.xib里面拖动需要的控件,并拖动给相应的控件添加属性,给登陆按钮添加事件. VCRoot.h文件里面: #import <UIKit/UIKit.h> @interface VCRoot : UIViewController //IBOutlet表示从xib中创建的 @property (weak, nonatomic) IBOutlet UITextField *mName; @propert

IOS的UITextField,UIButton,UIWebView的一些属性介绍和IOS图片资源的使用技巧

有时候UI给开发的资源跟实际的frame不一致,这个时候我们就要去拉伸图片 UIImage* image = [[UIImage imageNamed:@"text_field_bg.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:0]; //stretchableImageWithLeftCapWidth使图片有拉伸效果 UITextField的属性介绍: UITextField* field = [[UITextFiel

IOS简单的登陆界面

主要需要注意的几个问题: 1.导入图片方式最好用文件导入 代码: 在ViewController.m文件中 2.UILable常用属性 @property(nonatomic,copy)   NSString           *text; //设置文本内容 @property(nonatomic,retain) UIFont             *font; //设置字体 @property(nonatomic,retain) UIColor            *textColor;

IOS学习 03 QQ登陆界面

学习IOS开发,现在做一个简单的QQ登陆界面的开发,如下图: 1.1 创建项目和设计界面,界面就如上图,两个Label,两个个text,加上一个Button登陆按键,界面比较简单,如下图. 2.2 说下属性设置,在输入QQ号码的文本框里,在属性Placeholder中输入“请输入QQ号吗”,这个属性当程序起动时,就会自动的在QQ号码的输入文本框中显示. 2.3  设置text的属性Clear Button=Appears while editing.这个属性是在程序运行时,在文本框输入QQ号码时

Eclipse通过jdbc连接数据库制作简单登陆界面

一.前言: 做网站开发,要求有多种搭配方式,前台技术可以使用PHP.ASP.JSP.ASP.NET.CGI等任何一种: 需要用到的基础语言用的最多的就是HTML/CSS.JS.JAVA.XML这些了,HTML/CSS+JS可以实现对界面的描绘渲染,而JAVA则可以做后台数据处理,XML也是可以当作传输数据的介质(思考:XML比HTML强大这么多,为什么它没能替代HTML?): 这篇文章通过简单的JSP文件实现登陆界面,所以只用到了以下技术: HTML/CSS,简单演示就不做CSS样式了,可自行学

dede后台登陆又返回登陆界面怎么办

dede后台登陆又返回登陆界面......网上说的DATA等文件夹都有写入权限,试过好几种方法都不行! 其实最有可能的原因就是data文件夹的权限问题.大家可以通过FTP看下data文件的权限是否是775,也就是全部都有可读可写可执行的权限.记得把data文件的权限和sessions文件夹的权限改成777,用8Uftp软件进去以后,右键更改文件属性就可以了! 修改完这些以后记得用火狐或者遨游浏览器再登录下看看,360和IE记得要清空浏览器的缓存.第一步才是最重要的. .如果上面两步还不行的话就清