美文网首页
修改UITextField的leftView/rightView

修改UITextField的leftView/rightView

作者: 婉卿容若 | 来源:发表于2017-10-18 12:40 被阅读21次

    重写几个方法即可

    class RNSearchTextField: UITextField {
        
        //  重写
        override func leftViewRect(forBounds bounds: CGRect) -> CGRect {
            var padding = super.leftViewRect(forBounds: bounds)
            padding.origin.x += 5
            return padding
        }
        
        override func rightViewRect(forBounds bounds: CGRect) -> CGRect {
            var padding = super.rightViewRect(forBounds: bounds)
            padding.origin.x -= 5
            return padding
        }
        
        override func textRect(forBounds bounds: CGRect) -> CGRect {
            var padding = super.textRect(forBounds: bounds)
            padding.origin.x += 5
            return padding
        }
        
        override func editingRect(forBounds bounds: CGRect) -> CGRect {
            var padding = super.editingRect(forBounds: bounds)
            padding.origin.x += 5
            return padding
        }
        
        override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
            var padding = super.placeholderRect(forBounds: bounds)
            padding.origin.x += 5
            return padding
        }
    }
    

    `

    相关文章

      网友评论

          本文标题:修改UITextField的leftView/rightView

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