• UITextField


    #import "AppDelegate.h"

    //extension

    @interface AppDelegate ()<UITextFieldDelegate>

    @end

    @implementation AppDelegate

    - (void)dealloc

    {

        self.window = nil;

        [super dealloc];

    }

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        self.window = [[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];

        self.window.backgroundColor = [UIColor whiteColor];

        [self.window makeKeyAndVisible];

        

        self.window.rootViewController = [[UIViewController alloc] init];

        //

        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(50, 50, 300, 50)];

        /*

         UITextBorderStyleLine  黑色边框

         UITextBorderStyleRoundedRect  圆角边框

         */

        //设置边框样式

        textField.borderStyle = UITextBorderStyleRoundedRect;

        

        //设置/获取文本内容

        //    textField.text = @"I'm a text";

        //提示文本

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

        

        /*

         UITextFieldViewModeWhileEditing     编辑时出现

         UITextFieldViewModeAlways

         */

        //设置清除按钮

        textField.clearButtonMode = UITextFieldViewModeAlways;

        

        /*

         UITextAutocapitalizationTypeSentences  默认

         UITextAutocapitalizationTypeNone  开头字母小写

         */

        

        //设置开头字母大小写

        textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;

        

        /*

         UIKeyboardTypeNumbersAndPunctuation    数字加标点

         UIKeyboardTypeNumberPad                纯数字

         UIKeyboardTypeURL                      url

         */

        //设置键盘

        textField.keyboardType = UIKeyboardTypeURL;

        

        //设置return键

        textField.returnKeyType = UIReturnKeySearch;

        

        //是否密文文本

        textField.secureTextEntry = YES;

        

        //设置代理

        textField.delegate = self;

        

        [self.window addSubview:textField];

        [textField release];

        

        //让textField成为第一响应者

        //[textField becomeFirstResponder];

        

        return YES;

    }

    #pragma mark - UITextFieldDelegate

    //是否可以开始编辑   yes 才可以编辑

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

    {

        NSLog(@"%s", __func__);

        return YES;

    }

    //开始进入编辑状态

    - (void)textFieldDidBeginEditing:(UITextField *)textField

    {

        NSLog(@"%s", __func__);

    }

    //是否可以结束编辑  yes 可以结束

    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField

    {

        NSLog(@"%s", __func__);

        

        if (textField.text.length  < 6)

        {

            //警告视图创建

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"输入密码不足6位" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", @"ok1", @"ok2", nil];

            

            [alertView show];

            [alertView release];

            

            return NO;

        }

        return YES;

    }

    //进入结束编辑的状态

    - (void)textFieldDidEndEditing:(UITextField *)textField

    {

        NSLog(@"%s", __func__);

    }

    //点击return按钮的时候

    - (BOOL)textFieldShouldReturn:(UITextField *)textField

    {

        NSLog(@"%s", __func__);

        

        //取消第一响应者, 会回收键盘

        [textField resignFirstResponder];

        

        

        return  YES;

    }

    @end

  • 相关阅读:
    【转】浮点数与IEEE 754
    最小二乘
    黑科技!两行代码完美解决:同时设置overflow-x:hidden,overflow-y:visible无效的问题
    js过滤html标签
    react native 项目版本升级
    react-native中显示手机本地图片/视频
    SourceTree推送分支时遇到ArgumentException encountered错误的解决办法
    开发自己的react-native组件并发布到npm[转]
    react native 中实现个别页面禁止截屏
    JS数字转中文
  • 原文地址:https://www.cnblogs.com/chunji/p/5257460.html
Copyright © 2020-2023  润新知