美文网首页
修改UITextField的clearButton以及左侧图片等

修改UITextField的clearButton以及左侧图片等

作者: Timer丶 | 来源:发表于2018-01-24 15:02 被阅读581次

//修改clearButton的位置

- (CGRect)clearButtonRectForBounds:(CGRect)bounds{

    [super leftViewRectForBounds:bounds];

    CGRect rect = CGRectMake(bounds.size.width - 39,  11, 17, 22);

    return rect;

}

//修改左侧图片的位置

- (CGRect)leftViewRectForBounds:(CGRect)bounds{

    [super leftViewRectForBounds:bounds];

    CGRect rect = CGRectMake( 22,  11, 17, 22);

    return rect;

}

//  重写占位符的x值

- (CGRect)placeholderRectForBounds:(CGRect)bounds{

    CGRect placeholderRect = [super placeholderRectForBounds:bounds];

    placeholderRect.origin.x += 1;

    return placeholderRect;

}

//  重写文字输入时的X值

- (CGRect)editingRectForBounds:(CGRect)bounds{

    CGRect editingRect = [super editingRectForBounds:bounds];

    editingRect.origin.x += 11;

    return editingRect;

}

//  重写文字显示时的X值

- (CGRect)textRectForBounds:(CGRect)bounds{

    CGRect textRect = [super editingRectForBounds:bounds];

    textRect.origin.x += 11;

    return textRect;

}

- (CGRect)rightViewRectForBounds:(CGRect)bounds{

    UIView *view = self.rightView;

    NSLog(@"%@",view);

    if ([view isKindOfClass:[UIButton class]]) {

        UIButton *button = (UIButton *)view;

        for (UIView *view in button.subviews) {

            NSLog(@"%@",view);

            if ([view isKindOfClass:[UIImageView class]]) {

                CGRect rect = CGRectMake(bounds.origin.x + bounds.size.width - 22 - 17, bounds.origin.y + 11, 17, 22);

                return rect;

            }else if ([view isKindOfClass:[UILabel class]]){

                return CGRectMake(self.frame.origin.x + self.frame.size.width - 90, 0, 90, 44);

            }else{

                return CGRectMake(self.frame.origin.x + self.frame.size.width - 90, 0, 90, 44);

            }

        }

    }

    CGRect rect = CGRectMake(bounds.origin.x + bounds.size.width - 22 - 17, bounds.origin.y + 11, 17, 22);

    return rect;

}

相关文章

网友评论

      本文标题:修改UITextField的clearButton以及左侧图片等

      本文链接:https://www.haomeiwen.com/subject/qhsuaxtx.html