文章标题

来源:互联网 发布:守望先锋性能数据vrm 编辑:程序博客网 时间:2024/06/04 18:12
  • UITextField
    注:在.h文件中声明UITextFieldDelegage
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 74, self.view.frame.size.width - 20, 31)];textField.borderStyle = UITextBorderStyleRoundedRect;textField.placeholder = @"...";textField.clearButtonMode = UITextFieldViewModeWhileEditing;textField.secureTextEntry = YES;textField.keyboardType = UIKeyboardTypeEmailAddress;textField.returnKeyType = UIReturnKeyGo;textField.textColor = [UIColor cyanColor];textField.font = [UIFont boldSystemFontOfSize:16.0f];textField.delegate = self;textField.contentVerticalAlignment = UIViewContentModeCenter;[self.view addSubview:textField];

UITextField delegate

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField- {    - return Yes;- }- (void)textFieldDidEndEditing:(UITextField *)textField- {- }- (BOOL)textFieldShouldReturn:(UITextField *)textField- {    - [textField resignFirstResponder];    - return YES;- }

-UITextView
在.h文件中声明UITextViewDelegate

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(x, y, width, height)];textView.backgroundColor = [UIColor redColor];textView.textColor = [UIColor blackColor];textView.keyboardType = UIKeyboardTypeEmailAddress;textView.returnKeyType = UIReturnKeyGo;textView.delegate = self;[self.view addSubview:textView];

UITextView delegate

- (void)textViewDidEndEditing:(UITextView *)textView- {    - - }- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text- {    - if (text isEqualToString:@"n"]) {        - [textView resignFirstResponder];        - return NO;    - }    - return YES;- }
0 0
原创粉丝点击