UITextField
游標顏色,高度/寬度
//全部游標
[[UITextField appearance] setTintColor:[UIColor blackColor]];
//單個游標
_textField.tintColor = [UIColor redColor];
//寬高
- (CGRect)caretRectForPosition:(UITextPosition *)position
{
CGRect originalRect = [super caretRectForPosition:position];
originalRect.size.height = self.font.lineHeight + 2;
originalRect.size.width = 5;
return originalRect;
}
自動輸入
[_textField becomeFirstResponser];
禁用/關閉 貼上選擇全選
//部分關閉
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(paste:))//禁止貼上
return NO;
if (action == @selector(select:))// 禁止選擇
return NO;
if (action == @selector(selectAll:))// 禁止全選
return NO;
return [super canPerformAction:action withSender:sender];
}
//全部關閉
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
UIMenuController *menuController = [UIMenuController sharedMenuController];
if (menuController) {
[UIMenuController sharedMenuController].menuVisible = NO;
}
return NO;
}
初始設定
_textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
_textField.font = fontBoldCondensed11;
_textField.textColor = colorBlack000000;
_textField.tintColor = colorClear;
_textField.keyboardType = UIKeyboardTypeDecimalPad;
_textField.autocorrectionType = UITextAutocorrectionTypeNo;//自動改成正
_textField.spellCheckingType = UITextSpellCheckingTypeNo;//自動朗讀
_textField.autocapitalizationType = UITextAutocapitalizationTypeNone;//首字母大寫
_textField.placeholder = _L(@"MEMO_TAP_TO_INPUT");
_textField.rightView = self.phoneIndicatorView;
_textField.rightViewMode = UITextFieldViewModeNever;
[_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];