【问题标题】:First letter cuts off with Italic font in UITextFieldUITextField 中的第一个字母被斜体字体截断
【发布时间】:2015-04-08 17:00:14
【问题描述】:

我已将斜体字体添加到 UITextFieldUITextAlignmentLeft。当用户键入字符时,例如“j”,这个字符在左侧切断。我尝试添加填充、自定义textrectBoundseditingtextRectBounds,但它们都不起作用。

【问题讨论】:

  • 您是否尝试过更新插图?
  • 我已经尝试覆盖 UITextFeld (CGRect)editingRectForBounds:(CGRect)bounds { return CGRectInset(bounds, 2, 0);但这对我不起作用。第一个字母仍然被切断
  • 增加CGRectInset中dx的inset会发生什么,例如CGRectInset(bounds, 10, 0);
  • 它只是将编辑矩形移动到 10px 并且字符仍然从左边切断。
  • 这里也一样,改变插图移动文本但仍然切割斜体。我确实尝试过“textRectForBounds”+“editingRectForBounds”和“drawTextInRect”

标签: ios objective-c uitextfield


【解决方案1】:

你可以创建一个超简单的 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 值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-12
    • 2012-04-10
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多