admin 管理员组文章数量: 1086019
QQ登录界面01
目的:设计一个登录界面并实现登录功能
完成任务:1.熟悉UIButton、UILabel、UITextField的各种属性和应用;
2.动态创建控件,实现事件功能
3.掌握plist文件的读写
4.使用模态视图实现页面跳转
代码如下:
<strong><span style="font-size:18px;color:#006600;">// ViewContronller.m
// QQLogin
// Created by mac on 15-10-21.
// Copyright (c) 2015年 mac. All rights reserved.#import "NextViewController.h"
@interface ViewController ()
{UITextField *usernumber;UITextField *password;}
@end</span></strong>
<strong><span style="font-size:18px;color:#006600;">@implementation ViewController
- (void)viewDidLoad {[super viewDidLoad];[self initViews];[self plistMethod];// Do any additional setup after loading the view, typically from a nib.
}</span></strong>
<strong><span style="font-size:18px;color:#006600;">(void)initViews {UILabel *Userlab = [[UILabel alloc] initWithFrame:CGRectMake(30,100,70,30)];[Userlab setText:@"账号"];[Userlab setTextColor:[UIColor blueColor]];[Userlab setBackgroundColor:[UIColor clearColor]];[self.view addSubview:Userlab];UILabel *Passwordlab = [[UILabel alloc] initWithFrame:CGRectMake(30,140,70,30)];[Passwordlab setText:@"密码"];[Passwordlab setTextColor:[UIColor blueColor]];[Userlab setBackgroundColor:[UIColor clearColor]];[self.view addSubview:Passwordlab];usernumber = [[UITextField alloc] initWithFrame:CGRectMake(120,100 , 150, 30)];usernumber.placeholder=@"请输入账号";usernumber.clearButtonMode=UITextFieldViewModeWhileEditing;usernumber.borderStyle = UITextBorderStyleRoundedRect;[self.view addSubview:usernumber];password = [[UITextField alloc] initWithFrame:CGRectMake(120, 140, 150, 30)];password.placeholder=@"请输入密码";password.clearButtonMode=UITextFieldViewModeWhileEditing;password.borderStyle = UITextBorderStyleRoundedRect;password.secureTextEntry=YES;[self.view addSubview:password];UIButton *Registerbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];[Registerbtn setFrame:CGRectMake(90, 180, 150, 40)];[Registerbtn setTitle:@"注册" forState:UIControlStateNormal];[Registerbtn addTarget:self action:@selector(clickRegister:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:Registerbtn];UIButton *Loginbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];[Loginbtn setFrame:CGRectMake(150, 180, 150, 40)];[Loginbtn setTitle:@"登录" forState:UIControlStateNormal];[Loginbtn addTarget:self action:@selector(clickLogin:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:Loginbtn];<pre name="code" class="objc"> }
-(NSString *)plistMethod{//获取本地沙盒路径NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *Path = [paths objectAtIndex:0];//获取完整的文件名NSString *filename = [Path stringByAppendingPathComponent:@"messages.plist"];return filename;
}
<span style="font-family: Arial, Helvetica, sans-serif;">-(void)clickRegister:(UIButton *) sender{</span></span></strong>
<strong><span style="font-size:18px;color:#006600;"> //创建一个可变数组NSMutableArray,用来存放从文本框中获取的数据NSMutableArray *array=[[NSMutableArray alloc]init];[array addObject:usernumber.text];[array addObject:password.text];[array writeToFile:[self plistMethod] atomically:YES];//检查是否写入NSMutableArray *writeData=[[NSMutableArray alloc]initWithContentsOfFile:[self plistMethod]];NSLog(@"write data is:%@",writeData);}</span></strong>
<strong><span style="font-size:18px;color:#006600;"><span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>(void)clickLogin:(UIButton *)sender{//设置文件管理器NSFileManager *manage=[NSFileManager defaultManager];if ([manage fileExistsAtPath:[self plistMethod]]) {NSMutableArray *array = [[NSMutableArray alloc]initWithContentsOfFile:[self plistMethod]];NextViewController *nextCtr = [[NextViewController alloc] init];UINavigationController *navCtr = [[UINavigationController alloc] initWithRootViewController:nextCtr];//模态视图[self presentViewController:navCtr animated:YES completion:nil];NSLog(@"%@", array);} else{NSLog(@"数据文件不存在!!!");}
}
- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{[usernumber resignFirstResponder];[password resignFirstResponder];
}</span></strong>
@end
不足之处:1.未对注册和登录的具体事件进行判断处理
2.只能够做到将一组数据写进plist文件当中,后面写入的数据会覆盖掉前面的数据结语:学习之—>行路难,行路难,多少缓水是险滩
本文标签: QQ登录界面01
版权声明:本文标题:QQ登录界面01 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1686732231a30544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论