iOS UITextField rightView覆盖clear

作者: anny_4243 | 来源:发表于2016-11-23 19:14 被阅读1978次

    参考:http://blog.csdn.net/a394318511/article/details/8025170

    写一个UITextField的父类,重写UITextField内部边界绘制方法,更新UITextField内部控件布局

    #import "CustomTextField.h"
    
    @implementation CustomTextField
    
    //控制清除按钮的位置
    -(CGRect)clearButtonRectForBounds:(CGRect)bounds
    {
        return CGRectMake(bounds.origin.x + bounds.size.width - 55, bounds.origin.y, bounds.size.height, bounds.size.height);
    }
    //控制左视图位置
    - (CGRect)leftViewRectForBounds:(CGRect)bounds
    {
        CGRect inset = CGRectMake(bounds.size.width-30, bounds.origin.y, bounds.size.width-250, bounds.size.height);
        return inset;
    }
    //控制显示文本的位置
    -(CGRect)textRectForBounds:(CGRect)bounds
    {
        CGRect inset = CGRectMake(bounds.origin.x+10, bounds.origin.y, bounds.size.width -10, bounds.size.height);  
        return inset;
        
    }
    //控制编辑文本的位置
    -(CGRect)editingRectForBounds:(CGRect)bounds
    {
        CGRect inset = CGRectMake(bounds.origin.x +10, bounds.origin.y, bounds.size.width -10, bounds.size.height);
        return inset;
    }
    @end
    

    相关文章

      网友评论

        本文标题:iOS UITextField rightView覆盖clear

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