Together项目IOS平台开发04

来源:互联网 发布:阿里巴巴比淘宝贵2016 编辑:程序博客网 时间:2024/05/18 09:27

今天完成的是和上次的邮箱登录界面差不多的一个注册界面,主要包含了“用户名输入框”、“邮箱输入框”、“密码输入框”、“密码确认框”以及一个“注册”按钮。我使用的是4个UITextField以及一个UIButton。这个在设计上和之前的并没有什么差别,只是修改了下输入框内的提示文字,修改了位置。

另外一点在输入的时候,我修改了输入问题的安全属性,在密码的2个输入当中,让正常的文字以圆点方式显示,更加符合我们日常注册的习惯。

本来是想写一个判断两次密码是否相同的函数的,但是#selector中没发多元传参。可能会在下次予以实现。另外就是一样的,为了整个界面的美观,给了这个注册界面一个背景图片。

整体上来讲,使用的技术没有多大差别,通过点击上次的登录界面,就可以跳转到这次的注册界面。

连同上次修改过的登录界面和这次的注册界面的截图如下!




以下是我的代码

////  RegisterViewController.swift//  FinalTest////  Created by 沈力同 on 2017/5/10.//  Copyright © 2017年 沈力同. All rights reserved.//import UIKitclass RegisterViewController: UIViewController ,UITextFieldDelegate{        let screenSizeWidth = UIScreen.main.bounds.size.width        let screenSizeHeight = UIScreen.main.bounds.size.height        override func viewDidLoad() {        super.viewDidLoad()                self.view.backgroundColor = UIColor.white                let image_BG = UIImageView(image:UIImage(named:"IMG03.jpg"))                image_BG.frame = CGRect(x: 0, y: 0, width: screenSizeWidth, height: screenSizeHeight)                self.view.addSubview(image_BG)                //用户名框        let text00 = UITextField(frame:CGRect(x:5, y:127, width:screenSizeWidth-10, height:30))                text00.borderStyle = UITextBorderStyle.roundedRect                text00.alpha = 0.75                text00.placeholder = "请输入你的用户名"                text00.adjustsFontSizeToFitWidth=true  //当文字超出文本框宽度时,自动调整文字大小                text00.minimumFontSize=14  //最小可缩小的字号            text00.clearButtonMode = .whileEditing  //编辑时出现清除按钮                text00.textAlignment = .center //水平居中对齐                self.view.addSubview(text00)        //邮箱输入框        let text01 = UITextField(frame:CGRect(x:5, y:180, width:screenSizeWidth-10, height:30))                text01.borderStyle = UITextBorderStyle.roundedRect                text01.alpha = 0.75                text01.placeholder = "请输入你想要注册的邮箱"                text01.adjustsFontSizeToFitWidth=true  //当文字超出文本框宽度时,自动调整文字大小                text01.minimumFontSize=14  //最小可缩小的字号                text01.clearButtonMode = .whileEditing  //编辑时出现清除按钮                text01.textAlignment = .center //水平居中对齐                self.view.addSubview(text01)            //密码输入框        let text02 = UITextField(frame:CGRect(x:5, y:233, width:screenSizeWidth-10, height:30))                text02.borderStyle = UITextBorderStyle.roundedRect                text02.alpha = 0.75                text02.placeholder = "请输入你的登录密码"                text02.adjustsFontSizeToFitWidth=true  //当文字超出文本框宽度时,自动调整文字大小                text02.minimumFontSize=14  //最小可缩小的字号                text02.clearButtonMode = .whileEditing  //编辑时出现清除按钮                text02.textAlignment = .center //水平居中对齐                text02.isSecureTextEntry = true;                text02.delegate = self                self.view.addSubview(text02)                //密码确认框        let text03 = UITextField(frame:CGRect(x:5, y:286, width:screenSizeWidth-10, height:30))                text03.borderStyle = UITextBorderStyle.roundedRect                text03.alpha = 0.75                text03.placeholder = "请再次输入你的密码"                text03.adjustsFontSizeToFitWidth=true  //当文字超出文本框宽度时,自动调整文字大小                text03.minimumFontSize=14  //最小可缩小的字号                text03.clearButtonMode = .whileEditing  //编辑时出现清除按钮                text03.textAlignment = .center //水平居中对齐                text03.isSecureTextEntry = true;                text03.delegate = self                self.view.addSubview(text03)        //注册按钮        let button_register:UIButton = UIButton(type:.system)                button_register.layer.borderColor = UIColor.gray.cgColor;                button_register.layer.borderWidth = 2;                button_register.layer.cornerRadius = 5;                button_register.frame = CGRect(x:5, y:339, width:screenSizeWidth-10, height:50)                button_register.setTitle("注册", for:.normal)                button_register.addTarget(self, action: #selector(RegisterViewController.click_register), for: .touchUpInside)                self.view.addSubview(button_register)                button_register.setTitleColor(UIColor.white, for: .normal) //普通状态下文字的颜色                button_register.backgroundColor = UIColor.gray                           }        func click_register(text02:UITextField,text03:UITextField){                if (text02.text != text03.text) {                    let alertController = UIAlertController(title: "提示!",message: "两次密码不一致!",preferredStyle: .alert)                        let cancelAction = UIAlertAction(title: "确定", style: .cancel, handler: nil)                        alertController.addAction(cancelAction)                        self.present(alertController, animated: true, completion: nil)        }        if (text02.text == text03.text)        {//            let RegisterView = RegisterViewController()//            //            self.navigationController?.pushViewController(RegisterView, animated: true)                }            }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()    }}