我已使用 UITextAlignmentLeft
将斜体字体添加到 UITextField
。当用户键入字符时“j”,这个字符在左边被截断。我尝试添加填充、自定义 textrectBounds
和 editingtextRectBounds
但它们都不起作用。
最佳答案
您可以创建一个 super 简单的 UILabel 子类:
class PaddingLabel: UILabel {
override func drawText(in rect: CGRect) {
let insets = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 2)
super.drawText(in: rect.inset(by: insets))
}
}
然后,将您的 UILabel 类设为 PaddingLabel 并根据您的需要调整 insets 值。
关于ios - 第一个字母在 UITextField 中用斜体字体截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29520885/