如何在swift中为文本字段(UITextField)创建填充?我希望它是全局范围,所以当UIView加载每个Text字段时,这个填充都适用于它。
当前的Swift代码:
class MyCustomTextField: UITextField {
// Custom Code that i can't figure out.
}
我尝试采取的步骤:
先谢谢你。
Swift初学者:)
答案 0 :(得分:1)
class MyCustomTextField : UITextField {
var leftMargin : CGFloat = 10.0
override func textRectForBounds(bounds: CGRect) -> CGRect {
var newBounds = bounds
newBounds.origin.x += leftMargin
return newBounds
}
override func editingRectForBounds(bounds: CGRect) -> CGRect {
var newBounds = bounds
newBounds.origin.x += leftMargin
return newBounds
}
}