UITextField clearButtonMode color

前端 未结 5 571
甜味超标
甜味超标 2020-12-09 10:27

can I change the color of the clearButtonMode on a textField?

theTextField.clearButtonMode = UITextFieldViewModeWhileEditing

shows an x tha

5条回答
  •  佛祖请我去吃肉
    2020-12-09 11:01

    A cleaner way is to implement a category on UITextField with this method:

    - (void)modifyClearButtonWithImage:(UIImage *)image {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:image forState:UIControlStateNormal];
        [button setFrame:CGRectMake(0.0f, 0.0f, 15.0f, 15.0f)];
        [button addTarget:self action:@selector(clear:) forControlEvents:UIControlEventTouchUpInside];
        self.rightView = button;
        self.rightViewMode = UITextFieldViewModeWhileEditing;
    }
    
    -(IBAction)clear:(id)sender{
        self.text = @"";
    }
    

提交回复
热议问题