使用 uilabel等 制作的登陆页面 及页面跳转


#import "AppDelegate.h"
#import "LTView.h"



@interface AppDelegate ()
{
    UIView *_containerView;
    UIView *_rView;
    UIView *_pView;
    UIView *_lView;
}
@end


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        // Override point for customization after application launch.
    //新建一个工程,创建一个与window等大的视图containerView,然后用不同颜色的视图拼出一个注册界面。
    _containerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    _containerView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:_containerView];
    [_containerView release];
    
    _rView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    _rView.backgroundColor = [UIColor whiteColor];
    [_containerView addSubview:_rView];
    [_rView release];
    
    
    _pView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
   _pView.backgroundColor = [UIColor whiteColor];
    [_containerView addSubview:_pView];
    [_pView release];
    
    
    _lView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
   _lView.backgroundColor = [UIColor whiteColor];
    [_containerView addSubview:_lView];
    [_lView release];
    
    
    [self registerView];
    
    [self loginView];
    
    [self findPassword];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}


-(void)loginView{
    LTView *first = [[LTView alloc]initWithFrame:CGRectMake(30, 100, 260, 40) lalabelText:@"用户名" placeholder:@"请输入用户名" textFieldText:nil];
    [first setDelegate:self];
    [_lView addSubview:first];
    [first release];
    LTView *second = [[LTView alloc]initWithFrame:CGRectMake(30, 160, 260, 40) lalabelText:@"密码" placeholder:@"请输入密码" textFieldText:nil];
    [second setDelegate:self];
    [second setSecureEntry:YES];
    [_lView addSubview:second];
    
    
    UIButton *regist = [UIButton buttonWithType:UIButtonTypeSystem];
    regist.frame = CGRectMake(240, 230, 50, 30);
    regist.backgroundColor = [UIColor clearColor];
    regist.layer.cornerRadius = 8;
    [regist setTitle:@"注册" forState:UIControlStateNormal];
    [regist addTarget:self action:@selector(toRegist:) forControlEvents:UIControlEventTouchUpInside];
    [_lView addSubview:regist];
    UIButton *find = [UIButton buttonWithType:UIButtonTypeSystem];
    [find setTitle:@"找回密码" forState:UIControlStateNormal];
    find.backgroundColor = [UIColor clearColor];
    find.frame = CGRectMake(140, 230, 80, 30);
    find.layer.cornerRadius = 8;
    [find addTarget:self action:@selector(find:) forControlEvents:UIControlEventTouchUpInside];
    [_lView addSubview:find];
    UIButton *login = [UIButton buttonWithType:UIButtonTypeSystem];
    [login setTitle:@"登陆" forState:UIControlStateNormal];
    login.backgroundColor = [UIColor clearColor];
    login.frame = CGRectMake(50, 230, 50, 30);
    login.layer.cornerRadius = 8;
    [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
    [_lView addSubview:login];
}
-(void)login:(UIButton *)butten{
    
}
-(void)toRegist:(UIButton *)butten{
    [_containerView insertSubview:_rView atIndex:2];
}
- (void)find:(UIButton *)butten{
    [_containerView insertSubview:_pView atIndex:2];
}
-(void)findPassword
{
    UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 120, 40)];
    field.placeholder = @"请输入邮箱";
    field.borderStyle = UITextBorderStyleRoundedRect;
    [_pView addSubview:field];
    [field release];
    
    UIButton *find = [UIButton buttonWithType:UIButtonTypeSystem];
    find.frame = CGRectMake(80, 150, 50, 30);
    find.backgroundColor = [UIColor clearColor];
    find.layer.cornerRadius = 8;
    [find setTitle:@"找回" forState:UIControlStateNormal];
    [find addTarget:self action:@selector(findpast:) forControlEvents:UIControlEventTouchUpInside];
    [_pView addSubview:find];
    UIButton *cancle = [UIButton buttonWithType:UIButtonTypeSystem];
    [cancle setTitle:@"取消" forState:UIControlStateNormal];
    cancle.backgroundColor = [UIColor clearColor];
    cancle.frame = CGRectMake(160, 150, 80, 30);
    cancle.layer.cornerRadius = 8;
    [cancle addTarget:self action:@selector(cancleTo:) forControlEvents:UIControlEventTouchUpInside];
    [_pView addSubview:cancle];
}

-(void)findpast:(UIButton*)butten{
    
}
-(void)cancleTo:(UIButton *)butten{
    [_containerView insertSubview:_lView atIndex:2];
}
- (void)registerView{
    NSInteger y = 60;
    //数组  存储 label上显示的文字
    NSArray *lableText = @[@"用户名:",@"密码:",@"确认密码:",@"手机号:",@"邮箱:",@"住址:"];
    //存储 lalabelText 和 placeholder
    NSArray *placeholders = @[@"请输入用户名",@"请输入密码",@"请确认密码",@"请输入手机号",@"请输入邮箱邮箱",@"请输入住址"];
    
    
    for (int i = 0; i < 6; i++) {
        LTView *ltView = [[LTView alloc]initWithFrame:CGRectMake(30, y + 50 * i, 260, 30) lalabelText:lableText[i] placeholder:placeholders[i] textFieldText:nil];
        [ltView setDelegate:self];
        ltView.tag = 100 + i;
        if (i == 1 || i == 2) {
            //设置安全模式
            [ltView setSecureEntry:YES];
        } else if(i == 3){
            [ltView setKeyBoardType:UIKeyboardTypeNumberPad];
        }
        [_rView addSubview:ltView];
        [ltView release];
    }
    [self setupButten];
}
-(void)setupButten
{
    UIButton *regist = [UIButton buttonWithType:UIButtonTypeSystem];
    regist.frame = CGRectMake(80, 390, 50, 30);
    regist.backgroundColor = [UIColor clearColor];
    regist.layer.cornerRadius = 8;
    [regist setTitle:@"注   册" forState:UIControlStateNormal];
    [regist addTarget:self action:@selector(regist:) forControlEvents:UIControlEventTouchUpInside];
    [_rView addSubview:regist];
    UIButton *cancle = [UIButton buttonWithType:UIButtonTypeSystem];
    [cancle setTitle:@"取   消" forState:UIControlStateNormal];
    cancle.backgroundColor = [UIColor clearColor];
    cancle.frame = CGRectMake(160, 390, 80, 30);
    cancle.layer.cornerRadius = 8;
    [cancle addTarget:self action:@selector(cancle:) forControlEvents:UIControlEventTouchUpInside];
    [_rView addSubview:cancle];
}
-(void)regist:(UIButton *)butten{

}
-(void)cancle:(UIButton *)butten{
    [_containerView insertSubview:_lView atIndex:2];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
-(void)dealloc{
    [_window release];
    [super dealloc];
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    NSLog(@"hehe");
    return YES;
}// called when 'return' key pressed. return NO to ignore.
@end

#import "LTView.h"



@interface LTView ()
{
    UILabel *_desLable;
    UITextField *_textFiled;
}

@end

@implementation LTView




- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //左边一个 uilable  右边一个 uitextfeild
        // Initialization code
        //初始化时 完成内部封装控件的创建以及初始化
        
        CGFloat width = frame.size.width;
        CGFloat height = frame.size.height;
        
        _desLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0.3 * width, height)];
        _desLable.font = [UIFont systemFontOfSize:15];
        _desLable.textAlignment = NSTextAlignmentRight;
//        _desLable.backgroundColor = [UIColor grayColor];
        [self addSubview:_desLable];
        [_desLable release];
        
        
        _textFiled = [[UITextField alloc]initWithFrame:CGRectMake(0.4 * width, 0, 0.6 *width, height)];
        _textFiled.borderStyle = UITextBorderStyleRoundedRect;
//        _textFiled.backgroundColor = [UIColor yellowColor];
        _textFiled.autocapitalizationType = UITextAutocorrectionTypeNo;
        [self addSubview:_textFiled];
        [_textFiled release];
        
    }
    return self;
}

-(id)initWithFrame:(CGRect)frame lalabelText:(NSString *)labelText placeholder:(NSString *)placeholder textFieldText:(NSString *)textFieldText{
    self = [self initWithFrame:frame];
    if (self) {
        
        _desLable.text = labelText;
        _textFiled.placeholder = placeholder;
        _textFiled.text = textFieldText;
    }
    return self;
}
// 1 是否采用 安全模式
-(void)setSecureEntry:(BOOL)secureEntry{
    _textFiled.secureTextEntry = secureEntry;
}

//2 设置键盘类型
-(void)setKeyBoardType:(UIKeyboardType)keyBoardTape{
    _textFiled.keyboardType = keyBoardTape;
}
//设值 textfield 代理
-(void)setDelegate:(id<UITextFieldDelegate>)delegate{
    _textFiled.delegate = delegate;
}

-(NSString *)text{
    return _textFiled.text;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值