//
// ViewController.m
// QQ登陆界面
//
// Created by lanou on 16/7/14.
// Copyright © 2016年lanou. All rights reserved.
//
#import"ViewController.h"
@interfaceViewController()
//对使用的控件定义
@property(nonatomic,strong)UIButton*userbtn;
@property(nonatomic,strong)UIButton*denglubtn;
@property(nonatomic,strong)UILabel*zhlaber;
@property(nonatomic,strong)UILabel*mmlaber;
@property(nonatomic,strong)UITextField*textone;
@property(nonatomic,strong)UITextField*texttwo;
@property(nonatomic,strong)UIImageView*imageView;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
// _建立账号和密码标签
self.zhlaber= [[UILabelalloc]initWithFrame:CGRectMake(20,250,50,20)];
self.zhlaber.text=@"账号";
[self.viewaddSubview:self.zhlaber];
self.mmlaber= [[UILabelalloc]initWithFrame:CGRectMake(20,290,50,20)];
self.mmlaber.text=@"密码";
[self.viewaddSubview:self.mmlaber];
//建立文本
self.textone= [[UITextFieldalloc]initWithFrame:CGRectMake(90,240,200,40)];
self.texttwo= [[UITextFieldalloc]initWithFrame:CGRectMake(90,280,200,40)];
//开启密文
self.texttwo.secureTextEntry=YES;
//开启两种键盘
self.textone.keyboardType=UIKeyboardTypeDefault;
self.texttwo.keyboardType=UIKeyboardTypeNumberPad;
//输入文本文字
self.textone.placeholder=@"请输入账号";
self.texttwo.placeholder=@"请输入密码";
//将文本框及内容添加到视图上
[self.viewaddSubview:self.textone];
[self.viewaddSubview:self.texttwo];
//建立登录按钮
self.denglubtn= [[UIButtonalloc]initWithFrame:CGRectMake(100,350,200,40)];
UIImage*image = [UIImageimageNamed:@"login_btn_blue_nor.png"];
[self.denglubtnsetBackgroundImage:imageforState:(UIControlStateNormal)];
[self.viewaddSubview:self.denglubtn];
//为登录按钮添加响应动作
[self.denglubtnaddTarget:selfaction:@selector(loginaction)forControlEvents:UIControlEventTouchUpInside];
//添加头像按钮
self.userbtn= [[UIButtonalloc]initWithFrame:CGRectMake(150,60,80,80)];
UIImage*image2 = [UIImageimageNamed:@"login_header@2x.png"];
[self.userbtnsetBackgroundImage:image2forState:(UIControlStateNormal)];
//确定头像圆形半径和多余部分切除
self.userbtn.layer.cornerRadius=40;
self.userbtn.layer.masksToBounds=YES;
[self.viewaddSubview:self.userbtn];
//为头像按钮添加响应动作
[self.userbtnaddTarget:selfaction:@selector(userbtnClick)forControlEvents:(UIControlEventTouchUpInside)];
}
-(void)userbtnClick
{
UIImagePickerController*imagePicker=[[UIImagePickerControlleralloc]init];
//设置代理,到@interface后面遵守协议
imagePicker.delegate=self;
//弹出系统相册
[selfpresentViewController:imagePickeranimated:YEScompletion:nil];
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(nullableNSDictionary *)editingInfo
{
[self.userbtnsetBackgroundImage:imageforState:(UIControlStateNormal)];
[pickerdismissViewControllerAnimated:YEScompletion:nil];
//登录响应动作
} -(void)loginaction{
NSString*userstring,*passstring;
userstring =self.textone.text;
passstring =self.texttwo.text;
if(![userstringisEqualToString:@""]&&![passstringisEqualToString:@""]) {
NSLog(@"账号:%@",userstring);
NSLog(@"密码:%@",passstring);
}else{
UIAlertController*
tanchuang = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"账号密码不能为空"preferredStyle:UIAlertControllerStyleAlert];
[selfpresentViewController:tanchuanganimated:YEScompletion:nil];
UIAlertAction*okaction = [UIAlertActionactionWithTitle:@"确认"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {
}];
UIAlertAction*canaelaction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction){
}];
[tanchuangaddAction:okaction];
[tanchuangaddAction:canaelaction];
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
e��h�ry