zoukankan      html  css  js  c++  java
  • UITextField的简单操作和实际应用

    UITestField 

    UITestField* testField = [UITestField alloc]initWithFrame];

        /*

         

         设置边框样式

         typedef NS_ENUM(NSInteger, UITextBorderStyle) {

         UITextBorderStyleNone,     // 什么都没有(默认)

         UITextBorderStyleLine,     // 周围加黑色线条

         UITextBorderStyleBezel,    // 周围加灰色线条,上、左加阴影

         UITextBorderStyleRoundedRect  // 带圆角四周加灰色线条

         };

         textFeld.borderStyle = UITextBorderStyleRoundedRect;

         

         */

        例如:textField.borderStyle = UITextBorderStyleRoundedRect;

        textField.text = @"请输入密码";

        //设置提示文字

        textField.placeholder = @"请输入密码";

        //设置输入文字的颜色

        textField.textColor = [UIColor redColor];

        //开始编辑是否清除文本

        textField.clearsOnBeginEditing = YES;

        textField.textAlignment = NSTextAlignmentCenter;

        //设置字体

        textField.font = [UIFont systemFontOfSize:50];

        //字体适应宽度

        textField.adjustsFontSizeToFitWidth = YES;

        //设置最小字体

        textField.minimumFontSize = 1;

        //设置删除按钮的出现时间

        textField.clearButtonMode = UITextFieldViewModeWhileEditing;

        

        //设置textField的左视图

        UIView * small = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

        small.backgroundColor = [UIColor grayColor];

        

        textField.leftView = small;

        textField.leftViewMode = UITextFieldViewModeAlways;

        

        //设置安全密码

        textField.secureTextEntry = YES;

        

        /*

         

         设置键盘的样式

         typedef NS_ENUM(NSInteger, UIKeyboardType) {

         UIKeyboardTypeDefault,  默认键盘,支持所有字符      

         UIKeyboardTypeASCIICapable,支持ASCII的默认键盘   

         UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符

         UIKeyboardTypeURL,URL , 键盘,支持.com按钮 只支持URL字符    

         UIKeyboardTypeNumberPad,    数字键盘

         UIKeyboardTypePhonePad,      电话键盘

         UIKeyboardTypeNamePhonePad,   电话键盘,也支持输入人名

         UIKeyboardTypeEmailAddress,    用于输入电子 邮件地址的键盘

         UIKeyboardTypeDecimalPad   数字键盘 有数字和小数点    

         UIKeyboardTypeTwitter 优化的键盘,方便输入@、#字符

         };

         */   

       例如:textField.keyboardType = UIKeyboardTypeEmailAddress;

        

        /*

         return键变成什么键

         typedef NS_ENUM(NSInteger, UIReturnKeyType) {

         UIReturnKeyDefault, //默认 灰色按钮,标有Return

         UIReturnKeyGo,  //标有Go的蓝色按钮

         UIReturnKeyGoogle, //标有Google的蓝色按钮,用语搜索

         UIReturnKeyJoin, //标有Join的蓝色按钮

         UIReturnKeyNext, //标有Next的蓝色按钮

         UIReturnKeyRoute,  //标有Route的蓝色按钮

         UIReturnKeySearch, //标有Search的蓝色按钮

         UIReturnKeySend, //标有Send的蓝色按钮

         UIReturnKeyYahoo, //标有Yahoo的蓝色按钮

         UIReturnKeyDone,  //标有Done的蓝色按钮

         UIReturnKeyEmergencyCall, //紧急呼叫按钮

         };

         */

       例如:textField.returnKeyType = UIReturnKeyGo;

        /*

         输入字母大小写

         typedef NS_ENUM(NSInteger, UITextAutocapitalizationType) {

         UITextAutocapitalizationTypeNone, // 不自动大写 (默认)

         UITextAutocapitalizationTypeWords, // 单词首字母大写

         UITextAutocapitalizationTypeSentences, // 句子的首字母大写

         UITextAutocapitalizationTypeAllCharacters, // 所有字母都大写

         };  

         */

       例如:textField.autocapitalizationType = UITextAutocapitalizationTypeWords;

        

       //设置ReturnKey的禁止被选中

        self.enablesReturnKeyAutomatically=YES;

        self.textField = textField;    

        

        [self.view addSubview:textField];

        

    }

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

        

        //进行第一响应

        [self.textField becomeFirstResponder];

       //  取消第一响应

        [self.textField resignFirstResponder];

        

        //结束编辑

        [self.textField endEditing:YES];

        

        

    }

  • 相关阅读:
    UDP
    TCP
    python基础之socket编程
    单列模式
    元类
    issubclass()和isinstance()
    手持机设备公司(WINCE/ANDROID/LINUX)
    Android Hal 分析
    Android JNI 使用的数据结构JNINativeMethod详解
    MTK GPIO 一些理解
  • 原文地址:https://www.cnblogs.com/PSSSCode/p/5268701.html
Copyright © 2011-2022 走看看