美文网首页
10.31用户界面练习题

10.31用户界面练习题

作者: 冰凡513 | 来源:发表于2016-11-01 09:16 被阅读0次

    importUIKit

    classViewController:UIViewController{

    /*用户界面:

    1、键盘能够回收,提示点击按钮的时候键盘能回收,核心代码:[输入框:resignFirstResponder]

    2、密码和确认密码设置密文输入

    3、手机号使用数字键盘

    */

    overridefuncviewDidLoad() {

    super.viewDidLoad()

    letlabel =UILabel(frame:CGRectMake(30,60,60,20))

    view.addSubview(label)

    label.text="用户名"

    label.textColor=UIColor.blackColor()

    label.textAlignment= .Left

    label.font=UIFont.systemFontOfSize(15)

    lettextField =UITextField(frame:CGRectMake(100,60,200,20))

    view.addSubview(textField)

    textField.placeholder="用户名"

    textField.borderStyle= .RoundedRect

    textField.returnKeyType= .Go

    textField.delegate=self

    letlabel1 =UILabel(frame:CGRectMake(30,100,60,20))

    view.addSubview(label1)

    label1.text="密码"

    label1.textColor=UIColor.blackColor()

    label1.textAlignment= .Left

    label1.font=UIFont.systemFontOfSize(15)

    lettextField1 =UITextField(frame:CGRectMake(100,100,200,20))

    view.addSubview(textField1)

    textField1.placeholder="密码"

    textField1.secureTextEntry=true

    textField1.borderStyle= .RoundedRect

    textField1.returnKeyType= .Go

    textField1.delegate=self

    letlabel2 =UILabel(frame:CGRectMake(30,140,60,20))

    view.addSubview(label2)

    label2.text="确认密码"

    label2.textColor=UIColor.blackColor()

    label2.textAlignment= .Left

    label2.font=UIFont.systemFontOfSize(15)

    lettextField2 =UITextField(frame:CGRectMake(100,140,200,20))

    view.addSubview(textField2)

    textField2.placeholder="确认密码"

    textField2.secureTextEntry=true

    textField2.borderStyle= .RoundedRect

    textField2.returnKeyType= .Go

    textField2.delegate=self

    letlabel3 =UILabel(frame:CGRectMake(30,180,60,20))

    view.addSubview(label3)

    label3.text="手机号"

    label3.textColor=UIColor.blackColor()

    label3.textAlignment= .Left

    label3.font=UIFont.systemFontOfSize(15)

    lettextField3 =UITextField(frame:CGRectMake(100,180,200,20))

    view.addSubview(textField3)

    textField3.placeholder="手机号"

    textField3.keyboardType= .NumberPad

    textField3.borderStyle= .RoundedRect

    textField3.returnKeyType= .Go

    textField3.delegate=self

    letlabel4 =UILabel(frame:CGRectMake(30,220,60,20))

    view.addSubview(label4)

    label4.text="邮箱"

    label4.textColor=UIColor.blackColor()

    label4.textAlignment= .Left

    label4.font=UIFont.systemFontOfSize(15)

    lettextField4 =UITextField(frame:CGRectMake(100,220,200,20))

    view.addSubview(textField4)

    textField4.placeholder="邮箱"

    textField4.keyboardType= .EmailAddress

    textField4.borderStyle= .RoundedRect

    textField4.returnKeyType= .Go

    textField4.delegate=self

    }

    overridefuncdidReceiveMemoryWarning() {

    super.didReceiveMemoryWarning()

    // Dispose of any resources that can be recreated.

    }

    }

    extensionViewController:UITextFieldDelegate{

    //实现点击return键响应的方法

    functextFieldShouldReturn(textField:UITextField) ->Bool{

    //使键盘回收,所以取消输入框的第一响应者

    textField.resignFirstResponder()

    returntrue

    }

    }

    相关文章

      网友评论

          本文标题:10.31用户界面练习题

          本文链接:https://www.haomeiwen.com/subject/woqmuttx.html