zoukankan      html  css  js  c++  java
  • swift UITextField

          var textField = UITextField(frame: CGRectMake(10,160,200,30))

            //设置边框样式为圆角矩形

            textField.borderStyle = UITextBorderStyle.RoundedRect

            textField.delegate = self

            textField.placeholder = "请输入用户名"

            //文字大小超过文本框长度时自动缩小字号,而不是隐藏显示省略号

            textField.adjustsFontSizeToFitWidth=true  //当文字超出文本框宽度时,自动调整文字大小

          

            textField.minimumFontSize=14  //最小可缩小的字号

            /** 水平对齐 **/

            textField.textAlignment = .Right //水平右对齐

            

    //        textField.textAlignment = .Center //水平居中对齐

    //        textField.textAlignment = .Left //水平左对齐

            

            /** 垂直对齐 **/

            textField.contentVerticalAlignment = .Top  //垂直向上对齐

            textField.contentVerticalAlignment = .Center  //垂直居中对齐

            textField.contentVerticalAlignment = .Bottom  //垂直向下对齐

            //背景图片

    //        textField.background=UIImage(named:"background1");

            textField.clearButtonMode=UITextFieldViewMode.WhileEditing  //编辑时出现清除按钮

    //        textField.clearButtonMode=UITextFieldViewMode.UnlessEditing  //编辑时不出现,编辑后才出现清除按钮

    //        textField.clearButtonMode=UITextFieldViewMode.Always  //一直显示清除按钮

            textField.keyboardType = UIKeyboardType.Default

            textField.becomeFirstResponder()

            textField.returnKeyType = UIReturnKeyType.Done //表示完成输入

    //        textField.returnKeyType = UIReturnKeyType.Go //表示完成输入,同时会跳到另一页

    //        textField.returnKeyType = UIReturnKeyType.Search //表示搜索

    //        textField.returnKeyType = UIReturnKeyType.Join //表示注册用户或添加数据

    //        textField.returnKeyType = UIReturnKeyType.Next //表示继续下一步

    //        textField.returnKeyType = UIReturnKeyType.Send //表示发送

            self.view.addSubview(textField)

            

         //-------------简单的UIButton----------------

    //        [self .addButton()]

            

               }

        func textFieldShouldReturn(textField:UITextField) -> Bool

        {

            //收起键盘

            textField.resignFirstResponder()

            //打印出文本框中的值

            println(textField.text)

            return true;

        }

        //输入框字符串的变化

        func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool

        {

            

            println(textField.text)

            return true

        }

        

  • 相关阅读:
    第6章 键盘_6.5 插入符号(不是光标)
    第6章 键盘_6.3-6.4 字符消息、键盘消息和字符集
    第6章 键盘_6.1-6.2 键盘基础与击键消息
    第5章 绘图基础_5.6 矩形、区域和剪裁
    第4章 进程(1)
    第3章 内核对象(2)
    第3章 内核对象(1)
    第2章 字符和字符串处理(2)
    第2章 字符和字符串处理(1)
    第1章 错误处理
  • 原文地址:https://www.cnblogs.com/106dapeng/p/4798841.html
Copyright © 2011-2022 走看看