UITextField学习技巧

 UITextFiled练习

    // 用户名

    UITextField *userField = [[UITextField alloc] initWithFrame:CGRectMake(LOCATION_X + (CONTROL_WIDTH * 2) + 10, LOCATION_Y, CONTROL_WIDTH * 7, CONTROL_HEIGHT)];

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

    /*

边框样式

    typedef enum {

        UITextBorderStyleNone,

        UITextBorderStyleLine,

        UITextBorderStyleBezel,       

        UITextBorderStyleRoundedRect

    } UITextBorderStyle;

    */

    userField.borderStyle = UITextBorderStyleBezel;

    // 字体颜色

    userField.textColor = [UIColor blueColor];

    /* 

         字体对齐格式

    typedef enum {

    NSTextAlignmentLeft,     

    NSTextAlignmentCenter,

    NSTextAlignmentRight, 

    NSTextAlignmentRight,

    NSTextAlignmentCenter,

    } 

   */ 

    userField.textAlignment = NSTextAlignmentLeft;

    // 当编辑时文本框中的清除按钮

    userField.clearButtonMode = UITextFieldViewModeWhileEditing;

    userField.keyboardType = UIKeyboardTypeDefault;

    userField.keyboardAppearance = UIKeyboardAppearanceDefault;

    userField.returnKeyType = UIReturnKeyDone;

    // 文本框中未输入文字式,Done的键为灰色,不可点状态

    userField.enablesReturnKeyAutomatically = YES;

    // [userField becomeFirstResponder];

   // 代理方法 UITextFiledDelegate

   /*

   - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.

   - (void)textFieldDidBeginEditing:(UITextField *)textField;           // became first responder

   - (BOOL)textFieldShouldEndEditing:(UITextField *)textField;          // return YES to allow editing to stop  and to resign first responder status. NO to disallow the editing session to end

   - (void)textFieldDidEndEditing:(UITextField *)textField;             // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called

   - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;   // return NO to not change text

   - (BOOL)textFieldShouldClear:(UITextField *)textField;               // called when clear button pressed. return NO to ignore (no notifications)  清除按钮

   - (BOOL)textFieldShouldReturn:(UITextField *)textField;              // called when 'return' key pressed. return NO to ignore. 点击return,关闭键盘

*/ 


我关于UITextField常用的属性和方法就那么多,欢迎补充!!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值