/** UITextField是一个文本框,用于输入编辑文本
UILabel 主要是字体呈现,不具备字体编辑功能 */
UITextField *textField = [[UITextField alloc]init];
textField.delegate = self;//添加协议
/* 边框borderStyle
UITextBorderStyleNone:默认情况下状态,无边框
UITextBorderStyleLine:线性边框
UITextBorderStyleBezel:尖角的边框
UITextBorderStyleRoundedRect:圆角边框
*/
textField.borderStyle = UITextBorderStyleRoundedRect;
// ⚠️因为间接继承自UIView,所以可以通过layer来设置边框
1.文字的内容
textField.text = @"how are you,i am sly";
2.文字的相关属性:颜色,字体,大小,对齐方式等等
textField.textColor = [UIColor blueColor];
int i = (int)[UIFont familyNames].count;
textField.font = [UIFont fontWithName:[UIFont familyNames][i-2] size:20];
// 字体居上(默认上下居中)UITextField继承自UIControl,此类中有一个属性contentVerticalAlignment
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
// 字体居左(默认居左)
textField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动
textField.adjustsFontSizeToFitWidth = YES;
//再次编辑就清空
textField.clearsOnBeginEditing = YES;
/*其他属性
*1.清除按钮,即右方是否出现x号
*2.placeholder,当输入框没有内容时,水印提示
*3.secureTextEntry 密文显示
*/
textField.clearButtonMode = UITextFieldViewModeAlways;
/*
UITextFieldViewModeNever:从不出现
UITextFieldViewModeWhileEditing:编辑是出线
UITextFieldViewModeUnlessEditing:不编辑时出现
UITextFieldViewModeAlways:总是出现
*/
textField.placeholder = @"please input your phoneNumber";
网友评论