iOS_UITextField 基本操作

來源:互聯網
上載者:User

iOS_UITextField 基本操作
基本操作

UITextField *userNameTextField = [[UITextField alloc] init];    userNameTextField.frame = CGRectMake(30, 100, 220, 50);    [self.window addSubview:userNameTextField];    [userNameTextField release];    // 設定樣式    userNameTextField.borderStyle = UITextBorderStyleRoundedRect;    userNameTextField.placeholder = @"Enter your name";    userNameTextField.text = @"OUTLAN";    userNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing; // 設定右邊刪除按鈕出現時間    UILabel *leftLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];    leftLable.text = @"N";    // 設定左右視圖的顯示時間    userNameTextField.leftView = leftLable;    userNameTextField.leftViewMode = UITextFieldViewModeAlways;    [leftLable release];    userNameTextField.enabled = YES; // 設定是否允許輸入    userNameTextField.clearsOnBeginEditing = NO; // 輸入時清空    userNameTextField.secureTextEntry = NO; // 呈現圓點,一般用於輸入密碼    userNameTextField.keyboardAppearance = UIKeyboardAppearanceDark; // 修飾鍵盤顏色為黑    userNameTextField.keyboardType = UIKeyboardTypeEmailAddress; // 設定鍵盤樣式    userNameTextField.returnKeyType = UIReturnKeySearch; // 設定return按鍵的樣式    UIView *keyBoard = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 300)];    keyBoard.backgroundColor = [UIColor greenColor];//    userNameTextField.inputView = keyBoard; // 替換鍵盤    [keyBoard release];    UIView *inputAccessView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 20)];    inputAccessView.backgroundColor = [UIColor yellowColor];    userNameTextField.inputAccessoryView = inputAccessView; // 輔助條    [inputAccessView release];
收回鍵盤設定代理對象,通常為self
// 設定代理    textFiled.delegate = self;
當前類遵守協議
@interface AppDelegate : UIResponder 
實現協議方法
  - (BOOL)textFieldShouldReturn:(UITextField *)textField{    NSLog(@"點擊了Return");    [textField resignFirstResponder]; // 放棄第一響應者 收回鍵盤    return YES;}- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{    NSLog(@"begining");    return YES;}- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{    NSLog(@"ending");    return YES;} 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.