iOS UI02.2_UIView,UILabel,UIButton,UItextfield归纳

//

//  AppDelegate.m

//  UI02作业

//

//  Created by dllo on 15/7/30.

//  Copyright (c) 2015 zhozhicheng. All rights reserved.

//


#import "AppDelegate.h"


@interface AppDelegate ()

@property(nonatomic,retain)UITextField *numTextfield;

@property(nonatomic,retain)UITextField *passWordTextfield;

@property(nonatomic,assign)BOOL isSelected;

@property(nonatomic,retain)UIAlertView *alertView;

@property(nonatomic,assign)BOOL isClick;

@property(nonatomic,assign)UILabel *textlabel;

@end


@implementation AppDelegate

-(void)dealloc

{

    [_window release];

    [_numTextfield release];

    [_passWordTextfield release];

    [_alertView release];

    [_textlabel release];

    [super dealloc];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    [_window release];

    //创建一个和屏幕一样大的登陆界面

    UIView *loadView=[[UIView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];

    loadView.backgroundColor=[UIColor cyanColor];

    [self.window addSubview:loadView];

    [loadView release];

    //建立账号label

    UILabel *numLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 100, 80, 30)];

    [loadView addSubview:numLabel];

    numLabel.layer.borderWidth=1;

    numLabel.layer.cornerRadius=5;

    numLabel.text=@"账号";

    numLabel.textAlignment=NSTextAlignmentCenter;

    //release

    [numLabel release];

    //建立密码label

    UILabel *passWordLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 200, 80, 30)];

    [loadView addSubview:passWordLabel];

    passWordLabel.layer.borderWidth=1;

    passWordLabel.layer.cornerRadius=5;

    passWordLabel.text=@"密码";

    passWordLabel.textAlignment=NSTextAlignmentCenter;

    //release

    [passWordLabel release];

    //输入账号

    self.numTextfield=[[UITextField alloc] initWithFrame:CGRectMake(180, 100, 150, 30)];

    [loadView addSubview:self.numTextfield];

    [self.numTextfield release];

    self.numTextfield.layer.borderWidth=1;

    self.numTextfield.layer.cornerRadius=5;

    self.numTextfield.placeholder=@"请输入账号";

    self.numTextfield.clearButtonMode=UITextFieldViewModeAlways;

    self.numTextfield.keyboardType=UIKeyboardTypeNumberPad;

    //输入密码

    self.passWordTextfield=[[UITextField alloc] initWithFrame:CGRectMake(180, 200, 150, 30)];

    [loadView addSubview:self.passWordTextfield];

    [self.passWordTextfield release];

    self.passWordTextfield.layer.borderWidth=1;

    self.passWordTextfield.layer.cornerRadius=5;

    self.passWordTextfield.placeholder=@"请输入密码";

    self.passWordTextfield.secureTextEntry=YES;

    self.passWordTextfield.clearButtonMode=UITextFieldViewModeAlways;

    self.passWordTextfield.keyboardType=UIKeyboardTypeNumberPad;

    

    

    //设置显示密码

    UIButton *picButton=[UIButton buttonWithType:UIButtonTypeCustom];

    picButton.frame=CGRectMake(130,250, 30, 30);

    [picButton setImage:[UIImage imageNamed:@"check.png" ] forState:UIControlStateNormal];

    [loadView addSubview:picButton];

    [picButton addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];

    

    self.textlabel=[[UILabel alloc] initWithFrame:CGRectMake(180, 250, 150, 30)];

    self.textlabel.text=@"显示内容";

    [loadView addSubview:self.textlabel];

    [self.textlabel release];

    // 报错

    self.alertView=[[UIAlertView alloc] initWithTitle:@"报错" message:@"账号密码有误"  delegate:@"账号密码有错" cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];

    

    //设置tag

    loadView.tag=1000;

    //设置第二个界面

    UIView *enterView=[[UIView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];

    enterView.backgroundColor=[UIColor yellowColor];

    [self.window addSubview:enterView];

    [enterView release];

    //随便建立一个label,就是第二页显示的东西

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(120, 270, 150, 150)];

    [enterView addSubview:label];

    label.layer.borderWidth=1;

    label.layer.cornerRadius=75;

    label.text=@"哈哈哈哈哈";

    label.textAlignment=NSTextAlignmentCenter;

    //设置tag

    enterView.tag=1001;

    //设置登录按钮,并用来切换页面

    UIButton *loadButton=[UIButton buttonWithType:UIButtonTypeSystem];

    loadButton.frame=CGRectMake(100, 350, 80, 30);

    [loadView addSubview:loadButton];

    loadButton.layer.borderWidth=1;

    loadButton.layer.cornerRadius=5;

    [loadButton setTitle:@"登陆" forState:UIControlStateNormal];

    [loadButton addTarget:self action:@selector(changeView:) forControlEvents:UIControlEventTouchUpInside];

    //第二个界面加返回键

    UIButton *returnButton=[UIButton buttonWithType:UIButtonTypeSystem];

    returnButton.frame=CGRectMake(230, 430, 80, 30);

    [enterView addSubview:returnButton];

    returnButton.layer.borderWidth=1;

    returnButton.layer.cornerRadius=5;

    [returnButton setTitle:@"返回" forState:UIControlStateNormal];

    [returnButton addTarget:self action:@selector(returnView:) forControlEvents:UIControlEventTouchUpInside];

    //把登陆页面方法放到第一个

    [self.window bringSubviewToFront:[self.window viewWithTag:1000]];

    

    return YES;

}

-(void)changeImage:(UIButton *)picButton{

    if (picButton.selected) {

        //切换点击之后的两种图片状态

        [picButton setImage:[UIImage imageNamed:@"check.png"forState:UIControlStateNormal];

    }else{

        [picButton setImage:[UIImage imageNamed:@"checked.png"forState:UIControlStateNormal];

            }

    

    picButton.selected =!picButton.selected;

    self.passWordTextfield.secureTextEntry=!self.passWordTextfield.secureTextEntry;

    if (self.isSelected) {

        self.textlabel.text=@"不显示内容";

    }else {

        self.textlabel.text=@"显示内容";

    }

    self.isSelected = !self.isSelected;

    

    

    

}

//判断账号密码方法

-(void)changeView:(UIButton *)loadButton{

    if ([_numTextfield.text isEqualToString:@"1104010303"] && [_passWordTextfield.text isEqualToString:@"920928"] ) {

        [self.window bringSubviewToFront:[self.window viewWithTag:1001]];

        

    }else{

        [self.alertView show];

        [self.alertView release];

    }

    

}


-(void)returnView:(UIButton *)returnButton{

    if (self.isClick) {

        [self.window bringSubviewToFront:[self.window viewWithTag:1001]];

    }else{

        [self.window bringSubviewToFront:[self.window viewWithTag:1000]];

    }

}




- (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:.

}


@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值