【发布时间】:2016-09-10 22:49:40
【问题描述】:
【问题讨论】:
标签: ios swift swift2 uitextfield
【问题讨论】:
标签: ios swift swift2 uitextfield
我可以禁用这个转换
稍加小心,是的,您当然可以做到。文本的绘制实际上取决于你,如果你继承 UITextField: 你可以覆盖 drawText(in:) 和/或 textRect(forBounds:) 并负责文本的去向。
【讨论】:
textRectForBounds 方法吗?
editingRectForBounds(bounds:)。在这里找到我的答案:stackoverflow.com/questions/25367502/…
为了解决这个问题,我对UITextField 进行了子类化,并在子类中添加了以下内容:
class CustomTextField: UITextField {
override func editingRectForBounds(bounds: CGRect) -> CGRect {
let padding = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
return UIEdgeInsetsInsetRect(bounds, padding)
}
}
class CustomTextField: UITextField {
override func editingRect(forBounds bounds: CGRect) -> CGRect {
let padding = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
return bounds.inset(by: padding)
}
}
【讨论】: