美文网首页
UITextField的基本用法

UITextField的基本用法

作者: 曉明儿 | 来源:发表于2016-09-10 20:49 被阅读0次

    UItextField:

    一、UItextField概念:

    UItextField通常用于外部数据输入,以实现人机交互。下面以一个简单的登陆界面来讲解UItextField的详细使用。

    二、UItextField的初始化:

    eg: UITextField *tf = [[UITextField alloc]init];

    tf.frame = CGRectMake(100, 100, 200, 50);

    tf.delegate = self;

    tf.backgroundColor = [UIColor orangeColor];

    //更改提示信息内容

    tf.placeholder = @"请输入用户名";

    //更改return显示效果

    /*

    UIReturnKeyDefault,        -默认效果

    UIReturnKeyGo,            -开始

    UIReturnKeyGoogle,        -搜索

    UIReturnKeyJoin,          -加入

    UIReturnKeyNext,          -下一步

    UIReturnKeySearch,        -搜索

    UIReturnKeySend,          -发送

    UIReturnKeyYahoo,          -日本

    UIReturnKeyDone,          -结束

    UIReturnKeyEmergencyCall,

    */

    tf.returnKeyType = UIReturnKeyDone;

    //外观样式

    /**

    UIKeyboardAppearanceDefault,          // Default apperance for the current input method.

    UIKeyboardAppearanceDark NS_ENUM_AVAILABLE_IOS(7_0),

    UIKeyboardAppearanceLight NS_ENUM_AVAILABLE_IOS(7_0),

    UIKeyboardAppearanceAlert

    */

    tf.keyboardAppearance = UIKeyboardAppearanceDefault;

    //键盘类型

    /**

    UIKeyboardTypePhonePad - 电话键盘

    UIKeyboardTypeNumberPad - 纯数字

    UIKeyboardTypeEmailAddress - email地址键盘

    */

    tf.keyboardType = UIKeyboardTypeASCIICapable;

    //秘密输入

    tf.secureTextEntry = YES;

    //清空按键出现的时机

    tf.clearButtonMode = UITextFieldViewModeAlways;

    /**

    UITextBorderStyleNone,        -默认

    UITextBorderStyleLine,        -直线框

    UITextBorderStyleRoundedRect  -曲线框

    */

    tf.borderStyle =  UITextBorderStyleRoundedRect;

    //必写

    -(BOOL)textFieldShouldReturn:(UITextField *)textField

    {

    //取消键盘的第一相应,键盘收回

    [textField resignFirstResponder];

    return YES;

    }

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

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

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

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

    //-(BOOL)textFieldShouldEndEditing:(UITextField *)textField

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

    //用来控制输入内容的

    //-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

    相关文章

      网友评论

          本文标题:UITextField的基本用法

          本文链接:https://www.haomeiwen.com/subject/niayettx.html