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;
     }
  • 相关阅读:
    ZW网络团队及资源简介
    ZW云推客即将登场
    “4K云字库”基本框架图
    Sketch 55 Beta版本探秘,看看都有什么新功能
    产品经理有哪些类型?
    电影票APP原型设计分享– Movie Booking
    旅游类App的原型制作分享-Klook
    UI行业发展预测 & 系列规划的调整
    原来这就是 UI 设计师的门槛
    摹客PS插件全新改版!—— 智能检测不对应的设计稿
  • 原文地址:https://www.cnblogs.com/fcug/p/6308630.html
Copyright © 2011-2022 走看看