iOSUITextField的基本用法
UITextField *textField = [[UITextField alloc] init];//初始化
网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了邹城免费建站欢迎大家使用!
textField.userInteractionEnabled = YES;//是否可用
textField.text = @"UITextField"; //文字
textField.delegate = self; //代理
textField.frame = CGRectMake(100, 100, 100, 40); //大小和位置
textField.textColor = [UIColor redColor];// 字体颜色
textField.placeholder = @"UITextField";//提示字符
[textField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型UITextBorderStyleRoundedRect枚举类型
textField.secureTextEntry = YES; //密码框
textField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
UIImageView *imgv=[[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"right.png"]];
textField.rightView=imgv;
textField.rightViewMode = UITextFieldViewModeAlways; //右侧加图片
textField.font = [UIFont systemFontOfSize:14.0f];//文字的大小
textField.font = [UIFont boldSystemFontOfSize:14.0f];//文字加粗
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; //首字母是否自动大写
textField.clearsOnBeginEditing = YES; //再次编辑就清空
textField.adjustsFontSizeToFitWidth = YES; //设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动
textField.minimumFontSize = 20; //设置自动缩小显示的最小字体大小
textField.keyboardType = UIKeyboardTypeNumberPad; //设置键盘的样式
textField.backgroundColor = [UIColor grayColor];//背景颜色
//placeholder 颜色
//第一种
UIColor *color = [UIColor whiteColor];
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用户名" attributes:@{NSForegroundColorAttributeName: color}];
//第二种
[textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];//_placeholderLabel.textColor这个不可以修改
textField.returnKeyType =UIReturnKeyDone; //return键变成什么键
//文字上下居中
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//文字左右居中
textField.textAlignment = NSTextAlignmentCenter;
textField.keyboardAppearance=UIKeyboardAppearanceDefault; //键盘外观
//UITextField左边的距离
CGRect frame = [textField frame];
frame.size.width = 15;
UIView *leftview = [[UIView alloc] initWithFrame:frame];
textField.leftViewMode = UITextFieldViewModeAlways; //左边距为15pix
textField.leftView = leftview;
[textField becomeFirstResponder];//成为第一响应者
[self.view addSubview:textField];
分享标题:iOSUITextField的基本用法
分享URL:http://myzitong.com/article/jhhjps.html