IOS-UITextField


    //(1)创建

    UITextField *textField = [[UITextFieldalloc] init];

    

    //(2)设置默认显示的字

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

    

    //(3)密码 YES就是密文,NO 明文

    textField.secureTextEntry = NO;

    

    //(4)设置边框以及边框颜色和大小

//    UITextBorderStyleNone,无边框

//    UITextBorderStyleLine,有边框

//    UITextBorderStyleBezel,有边框和阴影

//    UITextBorderStyleRoundedRect圆角

    

    textField.borderStyle =UITextBorderStyleLine;

    //当设置borderStyleUITextBorderStyleRoundedRect会无效

//    textField.background = [UIImage imageNamed:@"image_photo"];


    //(5)设置边框大小和颜色

    textField.layer.borderWidth =1;

    textField.layer.borderColor = [UIColorredColor].CGColor;

    

//    textField.layer.masksToBounds = YES;

//    textField.layer.cornerRadius = 10;

    

    //(7)设置键盘自动大小写的属性

    textField.autocorrectionType =UITextAutocorrectionTypeNo;

    

    //(8)设置是否有自动纠错

//    UITextAutocorrectionTypeDefault, 默认

//    UITextAutocorrectionTypeNo,  不自动纠错

//    UITextAutocorrectionTypeYes, 自动纠错

    textField.autocapitalizationType =UITextAutocapitalizationTypeNone;

    

    //(9)设置左视图,可以起到距离左边框的作用

    UIView * leftview = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 20, textField.frame.size.height   )];//只有宽度起到了作用

    textField.leftView = leftview;

    leftview.backgroundColor = [UIColorwhiteColor];

    //要设置左视图模式

    textField.leftViewMode =UITextFieldViewModeAlways;

    

    //(10)设置右边视图会影响到清除键

    UIView * rightView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 20, textField.frame.size.height   )];//只有宽度起到了作用

    //textField.rightView = rightView;

    rightView.backgroundColor = [UIColorwhiteColor];

    //要设置右视图模式

    textField.rightViewMode =UITextFieldViewModeAlways;

    

    //(11)设置return键盘

//        UIReturnKeyDefault, 默认灰色按钮,标有Return

//        UIReturnKeyGo,      标有Go的蓝色按钮

//        UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索

//        UIReturnKeyJoin,标有Join的蓝色按钮

//        UIReturnKeyNext,标有Next的蓝色按钮

//        UIReturnKeyRoute,标有Route的蓝色按钮

//        UIReturnKeySearch,标有Search的蓝色按钮

//        UIReturnKeySend,标有Send的蓝色按钮

//        UIReturnKeyYahoo,标有Yahoo的蓝色按钮

//        UIReturnKeyYahoo,标有Yahoo的蓝色按钮

//        UIReturnKeyEmergencyCall, 紧急呼叫按钮


    textField.returnKeyType =UIReturnKeyDone;

    

    //(12)键盘类型

    //UIKeyboardTypeDefault,                //当前键盘(默认)

    //    UIKeyboardTypeASCIICapable,           //字母输入键

    //    UIKeyboardTypeNumbersAndPunctuation,  //数字和符号

    //    UIKeyboardTypeURL,                    URL键盘

    //    UIKeyboardTypeNumberPad,            数字键盘

    //    UIKeyboardTypePhonePad,             电话号码输入键盘

    //    UIKeyboardTypeEmailAddress, //邮件地址输入键盘

    

    textField.keyboardType =UIKeyboardTypeASCIICapable; //数字键

    

    //(13)键盘风格

    //    UIKeyboardAppearanceDefault默认外观,浅灰色

    //    UIKeyboardAppearanceAlert    深灰 石墨色

    textField.keyboardAppearance=UIKeyboardAppearanceDefault;


    //(14)首字母是否大写

//    UITextAutocapitalizationTypeNone, 不自动大写

//    UITextAutocapitalizationTypeWords,  单词首字母大写

//    UITextAutocapitalizationTypeSentences,  句子的首字母大写

//    UITextAutocapitalizationTypeAllCharacters, 所有字母都大写

    textField.autocapitalizationType =UITextAutocapitalizationTypeAllCharacters;//所有字母大写


    //(15)编辑时会出现个修改X,设置清除按钮模式


//        UITextFieldViewModeNever,从不出现

//        UITextFieldViewModeWhileEditing,编辑时显示

//        UITextFieldViewModeUnlessEditing,不编辑时

//        UITextFieldViewModeAlways  总是显示


    textField.clearButtonMode =UITextFieldViewModeWhileEditing;

    

    

    //(16)设置为YES当用点触文本字段时,字段内容会被清除

    textField.clearsOnBeginEditing =YES;

    

    

    //(17)设置为YES时文本会自动缩小以适应文本窗口大小。默认是保持原来大小,而让长文本滚动

    textField.adjustsFontSizeToFitWidth =YES;

    

    //(18)设置内容垂直方向

    textField.contentVerticalAlignment =UIControlContentVerticalAlignmentBottom;

    

    //(19)文字对齐方式

    textField.textAlignment =NSTextAlignmentRight;


    textField.frame = CGRectMake(20, 100, 200, 60);

    [self.viewaddSubview:textField];


    更多的话可以查看



  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值