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

        }

        

  • 相关阅读:
    Java——字符串操作
    算法——Java实现队列
    算法——Java实现栈
    算法——线性表之链式存储结构
    算法——线性表之顺序存储结构
    Java——单双引号的区别
    Hystrix源码解析
    Eureka源码探索(一)-客户端服务端的启动和负载均衡
    dubbo源码研究(一)
    dubbo-springboot入门级demo
  • 原文地址:https://www.cnblogs.com/106dapeng/p/4798841.html
Copyright © 2011-2022 走看看