UItextField:
一、UItextField概念:
UItextField通常用于外部數(shù)據(jù)輸入介陶,以實現(xiàn)人機交互。下面以一個簡單的登陸界面來講解UItextField的詳細使用色建。
二哺呜、UItextField的初始化:
eg: UITextField *tf = [[UITextField alloc]init];
tf.frame = CGRectMake(100, 100, 200, 50);
tf.delegate = self;
tf.backgroundColor = [UIColor orangeColor];
//更改提示信息內(nèi)容
tf.placeholder = @"請輸入用戶名";
//更改return顯示效果
/*
UIReturnKeyDefault,? ? ? ? -默認效果
UIReturnKeyGo,? ? ? ? ? ? -開始
UIReturnKeyGoogle,? ? ? ? -搜索
UIReturnKeyJoin,? ? ? ? ? -加入
UIReturnKeyNext,? ? ? ? ? -下一步
UIReturnKeySearch,? ? ? ? -搜索
UIReturnKeySend,? ? ? ? ? -發(fā)送
UIReturnKeyYahoo,? ? ? ? ? -日本
UIReturnKeyDone,? ? ? ? ? -結(jié)束
UIReturnKeyEmergencyCall,
*/
tf.returnKeyType = UIReturnKeyDone;
//外觀樣式
/**
UIKeyboardAppearanceDefault,? ? ? ? ? // Default apperance for the current input method.
UIKeyboardAppearanceDark NS_ENUM_AVAILABLE_IOS(7_0),
UIKeyboardAppearanceLight NS_ENUM_AVAILABLE_IOS(7_0),
UIKeyboardAppearanceAlert
*/
tf.keyboardAppearance = UIKeyboardAppearanceDefault;
//鍵盤類型
/**
UIKeyboardTypePhonePad - 電話鍵盤
UIKeyboardTypeNumberPad - 純數(shù)字
UIKeyboardTypeEmailAddress - email地址鍵盤
*/
tf.keyboardType = UIKeyboardTypeASCIICapable;
//秘密輸入
tf.secureTextEntry = YES;
//清空按鍵出現(xiàn)的時機
tf.clearButtonMode = UITextFieldViewModeAlways;
/**
UITextBorderStyleNone,? ? ? ? -默認
UITextBorderStyleLine,? ? ? ? -直線框
UITextBorderStyleRoundedRect? -曲線框
*/
tf.borderStyle =? UITextBorderStyleRoundedRect;
//必寫
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
//取消鍵盤的第一相應(yīng),鍵盤收回
[textField resignFirstResponder];
return YES;
}
//- (BOOL)textFieldShouldClear:(UITextField *)textField
//-(void)textFieldDidEndEditing:(UITextField *)textField
//-(void)textFieldDidBeginEditing:(UITextField *)textField
//-(BOOL)textFieldShouldReturn:(UITextField *)textField
//-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
//-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
//用來控制輸入內(nèi)容的
//-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string