您好,登錄后才能下訂單哦!
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];
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。