簡體   English   中英

如何為 UITextField 中的文本設置填充

[英]How can i set a Padding for the Text in UITextField

我想將文本放在另一個 position 中,但我不知道該怎么做? ,在屬性檢查器上沒有解決這個問題的選項嗎?

見 | 需要在箭頭指向的地方:

在此處輸入圖像描述

您可以制作自定義填充的 TextField。 你可以嘗試這樣的事情

class PaddedTextFeild: UITextField {
    let padding = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 5)
    override open func textRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
    }
    override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
    }
    override open func editingRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
    }
}

您可以嘗試按原樣使用此 class。 並更改第一行中定義的 UIEdgeInsets。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM