您的位置:首页 > 移动开发 > Swift

Swift语言--简单仿制QQ登录界面

2015-06-29 14:37 447 查看
开发工具:xcode6.32

仿制QQ登录界面,以供iOS开发者参考:

#import UIKit

class ViewController: UIViewController {

var QQnum = UITextField()
var passNum = UITextField()

override func viewDidLoad() {
super.viewDidLoad()
self .addAllSubViews()

// Do any additional setup after loading the view, typically from a nib.
}

func addAllSubViews() {

var ScreenW = UIScreen.mainScreen().bounds.width

print("Hello ,Swift!")
/// 头像
var headImage = UIImageView()
headImage.frame = CGRectMake(ScreenW/3, 30, 220, 200)
headImage.center = CGPointMake(ScreenW/2, 120)
// headImage.backgroundColor = UIColor.redColor()
headImage.image = UIImage(named: "icon1")
self.view.addSubview(headImage)

/// 输入qq号
var phoneLab = UILabel(frame: CGRectMake(30, 240, UIScreen.mainScreen().bounds.size.width-60, 30))

phoneLab.text = "请输入QQ号"

self.view.addSubview(phoneLab)

var QQnum = UITextField()
QQnum.frame = CGRectMake(30, 270, UIScreen.mainScreen().bounds.size.width-60, 30)
QQnum.placeholder = "请输入QQ号"
QQnum.layer.borderWidth = 1
QQnum.layer.borderColor = UIColor.lightGrayColor().CGColor
QQnum.layer.cornerRadius = 5
QQnum.keyboardType = UIKeyboardType.NumberPad
self.view.addSubview(QQnum)
self.QQnum = QQnum

/// 密码输入提示

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(30, 330, UIScreen.mainScreen().bounds.size.width-60, 30))

PassNumber.placeholder = "请输入密码"
PassNumber.secureTextEntry = true

PassNumber.layer.borderWidth = 1

PassNumber.layer.borderColor = UIColor.lightGrayColor().CGColor

PassNumber.layer.cornerRadius = 5
PassNumber.clearButtonMode  = UITextFieldViewMode.WhileEditing

self.view.addSubview(PassNumber)

self.passNum = PassNumber

/// 密码找回
var button = UIButton()
button.frame = CGRectMake(200, 360, 120, 30)
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: self, cancelButtonTitle: "取消").show()

// UIAlertView(title: "温馨提示", message: "新密码已发送至手机上", delegate: nil, cancelButtonTitle: "确定", otherButtonTitles: "取消").show()

}

/**

点击界面键盘辞去第一响应者

*/

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

self.QQnum.resignFirstResponder()

self.passNum.resignFirstResponder()

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios swift ui xcode ios开发