最佳答案
对于 textField,覆盖以下方法:
class InsetTextField: UITextField {
var inset: CGFloat = 10
override func textRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: inset, dy: 0)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: inset, dy: 0)
}
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: inset, dy: 0)
}
}
对于 TextView :
textView.contentInset = UIEdgeInsetsMake(inset, inset, inset, inset);
当 textView 完成编辑时,您可以参与,查看 this question .
关于ios - 更改 UITextField 中的文本布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42323588/