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)];
        }
        
    }
  • 相关阅读:
    word,excel,ppt转Pdf,Pdf转Swf,通过flexpaper+swftools实现在线预览
    Node做中转服务器,转发接口
    Vue——路由回退至指定页面
    Vue——前端生成二维码
    解决移动端键盘弹起导致的页面fixed定位元素布局错乱
    Vue——手机号、验证码登录(设置按钮60s禁用倒计时)
    Vue——解决报错 Computed property "****" was assigned to but it has no setter.
    typescript 起步之安装及配置 ts-node 环境变量
    区分 for...in 和 for...of
    解决HTML5(富文本内容)连续数字、字母不自动换行
  • 原文地址:https://www.cnblogs.com/jingdizhiwa/p/5614525.html
Copyright © 2011-2022 走看看