zoukankan      html  css  js  c++  java
  • iOS开发-UI (五)UITextField

    UITextField使用

       1.创建方式

     例:

      UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];

       2.常用方法和属性

         1)边框样式

           @property(nonatomic)  UITextBorderStyle   borderStyle; 

    UITextBorderStyleNone                       没有边框,背景默认为透明

    UITextBorderStyleLine                       线框,背景默认为透明

    UITextBorderStyleBezel bezel           风格边框,背景默认为透明

    UITextBorderStyleRoundedRect         圆角边框,背景默认为白色

    textField.borderStyle = UITextBorderStyleBezel;

         2)提示文字: placeholder 

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

         3)键盘类型: keyboardType

    textField.keyboardType = UIKeyboardTypeNumberPad;

         4)键盘样式: keyboardAppearance

    textField.keyboardAppearance = UIKeyboardAppearanceLight;

         5)密文输入: secureTextEntry 

    textField.secureTextEntry = YES;

         6)再次编辑是否清空: clearsOnBeginEditing

    textField.clearsOnBeginEditing = YES;

         7)文本横向对齐方式: textAlignment

    textField.textAlignment = NSTextAlignmentRight;

         8)文本滚动: adjustsFontSizeToFitWidth 

    搭配 minimumFontSize一起使用

    //回收键盘

        [self.view endEditing: YES];

         9)return键类型:returnKeyType

    @property(nonatomic) UIReturnKeyType returnKeyType; 

    UIReturnKeyDefault,

        UIReturnKeyGo,

        UIReturnKeyGoogle,

        UIReturnKeyJoin,

        UIReturnKeyNext,

        UIReturnKeyRoute,

        UIReturnKeySearch,

        UIReturnKeySend,

        UIReturnKeyYahoo,

        UIReturnKeyDone,

        UIReturnKeyEmergencyCall,

         10)清理按钮模式:clearButtonMode

    @property(nonatomic)        UITextFieldViewMode  clearButtonMode;

    UITextFieldViewModeNever,

        UITextFieldViewModeWhileEditing,

        UITextFieldViewModeUnlessEditing,

        UITextFieldViewModeAlways

       3.UITextFieldDelegate 协议

         1)是否可以进入编辑模式

         - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;

    //返回NO,无法进入编辑状态

        return YES;

         2)文本框已经进入编辑模式

         -(void)textFieldDidBeginEditing:(UITextField *)textField;

         3)文本框是否可以结束编辑模式

         -(BOOL)textFieldShowEndEditing:(UITextField *)textField;

    //返回NO,无法结束编辑状态

        return YES;

         4)文本框已结束编辑模式

         -(void)textFieldDidEndEditing:(UITextField *)textField;

         5)是否可以点击clear按钮

         -(BOOL)textFieldShouldClear:(UITextField *)textField;

    //返回NO,点击clear按钮无响应

        return YES;

         6)是否可以点击return按钮

         -(BOOL)textFieldShouldReturn:(UITextField *)textField;

        //移除第一响应者

        [textField resignFirstResponder];   

        return YES;

         7)允许修改内容

         

    - (BOOL)textField:(UITextField *)textField 
    
    shouldChangeCharactersInRange:(NSRange)range 
    
        replacementString:(NSString *)string;
    
      例如:
    
    if (textField.text.length >= 6) {      
            if ([string isEqualToString:@""]) {
    
                return YES;
            }
            return NO;
    
        }
        return YES;
     }
  • 相关阅读:
    VOA 2009/11/02 DEVELOPMENT REPORT In Kenya, a Better Life Through Mobile Money
    2009.11.26教育报道在美留学生数量创历史新高
    Java中如何实现Tree的数据结构算法
    The Python Tutorial
    VOA HEALTH REPORT Debate Over New Guidelines for Breast Cancer Screening
    VOA ECONOMICS REPORT Nearly Half of US Jobs Now Held by Women
    VOA ECONOMICS REPORT Junior Achievement Marks 90 Years of Business Education
    VOA 2009/11/07 IN THE NEWS A Second Term for Karzai; US Jobless Rate at 10.2%
    Ant入门
    Python 与系统管理
  • 原文地址:https://www.cnblogs.com/fcug/p/6308630.html
Copyright © 2011-2022 走看看