zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    DB2 java.lang.NoClassDefFoundError:com/ibm/db2/jcc/SQLJContext
    JavaScript字符串split方法
    使用 WebSphere Application Server Community
    为DB2数据库创建新用户帐户并为其分配特定特权
    Servlet3.0之一:Servlet3.0新特性介绍
    window下jni调用dll和linux下jni调用so库(转)
    分表分库之三:中间件介绍
    jboss5 启动时报HsqlException:length must be specified in type definition:VARBINARY错误
    J2EE Formbased Authentication
    阻塞队列之七:DelayQueue延时队列
  • 原文地址:https://www.cnblogs.com/chunji/p/5257460.html
Copyright © 2011-2022 走看看