iOS开发——实用篇Swift篇&QQ登入界面实现

时间:2024-10-12 16:37:13

QQ登入界面实现

我们知道在App Store中几乎所有软件都设计到账户的登入,而我们最常见的就是QQ,微信,在没有踏入程序员这条不归路之前,看到一个个的界面都感觉好高大上的样子。

在学习的过程中,自己就照着手机上面APP自己比较好奇的界面实现了一下,今天分享一下关于QQ登入界面,完全纯代码,实用StoryBoar太麻烦,个人比较喜欢用代码实现,而几乎所有登入界面几乎都是一样的,只是图标不同,或者还会有其他的拓展功能,不过这里都会了其他的*不是事儿。

废话不多说,直接上代码

import UIKit

class ViewController: UIViewController {

/// 定义属性
var QQNumber = UITextField()
var PassNumber = UITextField()

    override func viewDidLoad() {

        self.view.backgroundColor = UIColor.whiteColor()
        super.viewDidLoad()

        // 添加头图片
        [self .addAllSubViews()];
    }

    // 添加所有子控件
    func addAllSubViews(){

        /// 头像
       /var headImage = UIImageView(frame: CGRectMake(, , , ))
        headImage.image =  UIImage(named:"QQ.png")
        self.view.addSubview(headImage)

        /// QQ号输入提示
       // var phoneText = UILabel(frame: CGRectMake(30, 240, UIScreen.mainScreen().bounds.size.width-60, 30))
       // phoneText.text = "请输入QQ号"
        //self.view.addSubview(phoneText)

        /// QQ号输入框
        var QQNumber = UITextField(frame: CGRectMake(, , UIScreen.mainScreen().bounds.size.width-, ))
        QQNumber.placeholder = "请输入QQ号"
        QQNumber.layer.borderWidth =
        QQNumber.layer.borderColor = UIColor.lightGrayColor().CGColor
        QQNumber.layer.cornerRadius =
        QQNumber.keyboardType = UIKeyboardType.NumberPad
        self.view.addSubview(QQNumber)
        self.QQNumber = QQNumber

        /// 密码输入提示
        //var passText = UILabel(frame: CGRectMake(30, 300, UIScreen.mainScreen().bounds.size.width-60, 30))
        //passText.text = "请输入密码"
        //self.view.addSubview(passText)

        /// 密码输入框
        var PassNumber = UITextField(frame: CGRectMake(, , UIScreen.mainScreen().bounds.size.width-, ))
        PassNumber.placeholder = "请输入密码"
        PassNumber.layer.borderWidth =
        PassNumber.layer.borderColor = UIColor.lightGrayColor().CGColor
        PassNumber.layer.cornerRadius =
        self.view.addSubview(PassNumber)
        self.PassNumber = PassNumber

        /// 密码找回
        var button = UIButton(frame: CGRectMake(, , , ))
        UIButton.buttonWithType(UIButtonType.Custom)
        button.setTitle("忘记密码", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        self.view.addSubview(button)
        button.addTarget(self, action: "onClick", forControlEvents: UIControlEvents.TouchUpInside)

    }

       /// 密码找回方法实现
    func onClick(){

        ///找回密码提示
    UIAlertView(title: "温馨提示", message: "新密码已发送至手机上", delegate: nil, cancelButtonTitle: "确定", otherButtonTitles: "取消").show()
    }
    /**
    点击界面键盘辞去第一响应者
    */
    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

        self.QQNumber.resignFirstResponder()
        self.PassNumber.resignFirstResponder()
    }

}