重写几个方法即可
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
}
}
`
网友评论