標籤:
我們知道在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(50, 30, 220, 200)) 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(30, 270, UIScreen.mainScreen().bounds.size.width-60, 30)) QQNumber.placeholder = "請輸入QQ號" QQNumber.layer.borderWidth = 1 QQNumber.layer.borderColor = UIColor.lightGrayColor().CGColor QQNumber.layer.cornerRadius = 5 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(30, 330, UIScreen.mainScreen().bounds.size.width-60, 30)) PassNumber.placeholder = "請輸入密碼" PassNumber.layer.borderWidth = 1 PassNumber.layer.borderColor = UIColor.lightGrayColor().CGColor PassNumber.layer.cornerRadius = 5 self.view.addSubview(PassNumber) self.PassNumber = PassNumber /// 密碼找回 var button = UIButton(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: nil, cancelButtonTitle: "確定", otherButtonTitles: "取消").show() } /** 點擊介面鍵盤辭去第一響應者 */ override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { self.QQNumber.resignFirstResponder() self.PassNumber.resignFirstResponder() } }
iOS開發——實用篇Swift篇&QQ登入介面實現