zoukankan      html  css  js  c++  java
  • UITextField

        // 设置文本框左边的内容 文本框内小间距
        UIView *leftView = [[UIView alloc] init];
        leftView.frame = CGRectMake(0, 0, 10, 0);
        self.messageField.leftView = leftView;
        self.messageField.leftViewMode = UITextFieldViewModeAlways
    键盘处理:
    // 监听键盘通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } #pragma mark - 键盘处理 - (void)keyboardWillShow:(NSNotification *)note { // 取出键盘最终的frame CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; // 取出键盘弹出需要花费的时间 double duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 修改约束 self.bottomSpacing.constant = rect.size.height; [UIView animateWithDuration:duration animations:^{ [self.view layoutIfNeeded]; }]; } - (void)keyboardWillHide:(NSNotification *)note { // 取出键盘弹出需要花费的时间 double duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 修改约束 self.bottomSpacing.constant = 0; [UIView animateWithDuration:duration animations:^{ [self.view layoutIfNeeded]; }]; }

    第二种方式:
    // 监听键盘通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
    }

    - (void)dealloc
    {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }

    #pragma mark - 键盘处理
    - (void)keyboardWillChangeFrame:(NSNotification *)note {
        // 取出键盘最终的frame
        CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
        NSLog(@"%@",[NSValue valueWithCGRect:rect]);
        // 取出键盘弹出需要花费的时间
        double duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
        
        // 修改约束
        self.bottomSpacing.constant = [UIScreen mainScreen].bounds.size.height - rect.origin.y;
        [UIView animateWithDuration:duration animations:^{
            [self.view layoutIfNeeded];
        }];
    }

     添加事件:

    .....
    [textfield addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    }
    - (void)textFieldDidChange:(UITextField *)textField
    {
        if ((textField.tag-100)%3==1) {
            if (textField.text.length > 2) {
                textField.text = [textField.text substringToIndex:2];
            }
        }
        if ([textField.text hasSuffix:@"."]) {
            textField.text = [textField.text substringToIndex:(textField.text.length-1)];
        }
        
    }
  • 相关阅读:
    七牛云的 python sdk 是如何 批量删除资源的
    mysql 主从复制
    django3上线部署踩的坑
    基于linux在线预览
    数据库2
    数据库3
    安装 webstorm--->vue
    Django基础1
    pymysql基础
    前段之jQuery
  • 原文地址:https://www.cnblogs.com/jingdizhiwa/p/5614525.html
Copyright © 2011-2022 走看看