• 记录UITextField删除状态


    self.testTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    self.testTextField.leftViewMode = UITextFieldViewModeAlways;

    这两机代码可以是textField的光标向右偏移40;

    ============================

    项目中需要在UITextField在删除时候的做些事情,本身又没有方法。所以需要自己写

    KeyInPutTextField.h

    #import <UIKit/UIKit.h>
    
    @protocol  KeyInPutTextFieldDelegate<NSObject>
    
    @optional
    - (void)deleteBackward;
    
    @end
    
    @interface KeyInPutTextField : UITextField
    
    @property (nonatomic, assign)id<KeyInPutTextFieldDelegate>keyInputDelegate;
    
    @end

    KeyInPutTextField.m

    #import "KeyInPutTextField.h"
    
    @implementation KeyInPutTextField
    
    - (void)deleteBackward
    {
        [super deleteBackward];
        if ((_keyInputDelegate &&[_keyInputDelegate respondsToSelector:@selector(deleteBackward)]))
        {
            [_keyInputDelegate deleteBackward];
        }
    }
    
    @end

    调用

    #import "ViewController.h"
    #import "KeyInPutTextField.h"
    @interface ViewController ()<UITextFieldDelegate, KeyInPutTextFieldDelegate>
    
    @property (nonatomic, strong) KeyInPutTextField *testTextField;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.testTextField = [[KeyInPutTextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];
        self.testTextField.borderStyle = UITextBorderStyleRoundedRect;
        self.testTextField.textColor = [UIColor redColor];
        self.testTextField.delegate = self;
        self.testTextField.keyInputDelegate = self;
        [self.view addSubview:self.testTextField];
        [self.testTextField becomeFirstResponder];
        
        
        self.testTextField.rightViewMode = UITextFieldViewModeAlways;
        
        
        self.testTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        self.testTextField.leftViewMode = UITextFieldViewModeAlways;
    }
    
    
    - (void)deleteBackward
    {
        NSLog(@"aa");
    }
  • 相关阅读:
    登录校验
    com.sd.utils/Druidutils.java-连接池
    软件开发流程
    JSP九大内置对象
    . net程序员应该会什么(转载自知乎博主:专注.net领域极客)
    WPF 在属性栏中更改相关设置
    office 2016 专业版 删除部分组件
    AutoMapper安装及基本用法
    sql 求一张表中 列值重复中的 不同列值中的更新时间最大值对应的 全列数据,即相同的列值取时间最晚的哪一行
    C# 多线程 lock
  • 原文地址:https://www.cnblogs.com/menglingxu/p/6137357.html
Copyright © 2020-2023  润新知