我想为我的UITextFields使用一个自定义的背景。除了我必须使用UITextBorderStyleNone使它看起来更漂亮之外,它工作得很好。这会强制文本在没有任何填充的情况下粘贴到左侧。
除了使用我的自定义背景图像之外,我可以手动设置一个填充,使其看起来与UITextBorderStyleRoundedRect相似吗?
发布于 2014-12-19 02:28:31
适用于Xcode >6的Swift 3版本,其中您可以在Interface Builder / Storyboard中编辑插入值。
import UIKit
@IBDesignable
class FormTextField: UITextField {
@IBInspectable var inset: CGFloat = 0
override func textRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: inset, dy: inset)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
return textRect(forBounds: bounds)
}
}

https://stackoverflow.com/questions/3727068
复制相似问题