更改UITextField中的文本布局

加布·庞德

下面是一些UITextField的图像。关于底部的大字体,如何使它在左上角(而不是中间)开始文本,以及如何使它们全部从右头开始。如您所见,它们尴尬地靠近左边缘。


在此处输入图片说明

飞机

您可以订阅自定义TextField:

import UIKit

class CustomTextField: UITextField {

    var inset:CGFloat = 12  // You can set the inset you want

    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)
    }

}

结果,您可以看到CustomTextField的插图:


编辑

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章