(1)UITextField设置placeholder及其字体颜色
如果不先设置占位文字, 占位文字的颜色是不管用的:
searchBar.placeholder=@"输入昵称";
[searchBar setValue:[UIColor lightGrayColor]forKeyPath:@"_placeholderLabel.textColor"];
(2)returnButton为"搜索"时,没有文字,搜索键不可点
searchBar.returnKeyType=UIReturnKeySearch;
searchBar.enablesReturnKeyAutomatically=YES;//这里设置为无文字就灰色不可点
(3)首字母是否大写
text.autocapitalizationType = UITextAutocapitalizationTypeNone;
typedef enum {
UITextAutocapitalizationTypeNone, 不自动大写
UITextAutocapitalizationTypeWords, 单词首字母大写
UITextAutocapitalizationTypeSentences, 句子的首字母大写
UITextAutocapitalizationTypeAllCharacters, 所有字母都大写
} UITextAutocapitalizationType;
(4)是否纠错
text.autocorrectionType = UITextAutocorrectionTypeNo;
typedef enum {
UITextAutocorrectionTypeDefault, 默认
UITextAutocorrectionTypeNo, 不自动纠错
UITextAutocorrectionTypeYes, 自动纠错
} UITextAutocorrectionType;
(5)再次编辑就清空
text.clearsOnBeginEditing = YES;
(6)键盘外观
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
typedef enum {
UIKeyboardAppearanceDefault, 默认外观,浅灰色
UIKeyboardAppearanceAlert, 深灰 石墨色
} UIReturnKeyType;
(7)每四位加一个空格,实现代理
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// 四位加一个空格
if([stringisEqualToString:@""])
{
// 删除字符
if((textField.text.length -2) %5==0)
{
textField.text = [textField.text substringToIndex:textField.text.length -1];
}
returnYES;
}
else
{
if(textField.text.length %5==0){
textField.text = [NSString stringWithFormat:@"%@ ", textField.text];}
}
returnYES; }
}
(8)自定义 select状态下复制粘贴等操作
继承UITextView的textView中 重写方法
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
UIMenuItem*reply = [[UIMenuItemalloc]initWithTitle:@"评论"action:@selector(reply)];
UIMenuItem*copy1 = [[UIMenuItemalloc]initWithTitle:@"复制"action:@selector(copy1)];
UIMenuController*menu = [UIMenuControllersharedMenuController];
[menusetMenuItems:[NSArrayarrayWithObjects:copy1,reply,nil]];
if(action ==@selector(reply)||action ==@selector(copy1)) {
returnYES;
}
returnNO;
}
网友评论