【发布时间】:2019-12-29 18:48:34
【问题描述】:
我的问题是我想为一个文本字段放置 2 个占位符。一个占位符应该在左边,另一个应该在右边。
我的代码:
func returnPlaceHolder(first: String, second: String, textField: UITextField){
let width: Int = Int(textField.bounds.width * 0.2)
let spaceValue = width - (first.count + second.count)
var temp = "\(first) "
let tempCount = spaceValue - (first.count + second.count)
var value = String()
for _ in 0..<tempCount {
temp.append(" ")
}
value = "\(temp) \(second)"
textField.placeholder = value
textField.setLeftPaddingPoints(10)
textField.setRightPaddingPoints(10)
}
我目前正在使用此功能来创建空格.. 但我的问题是多个文本字段的空格不会相同,我希望它们对齐..
就像这张照片:https://imgur.com/pZZMoNv
这是我当前代码得到的结果:https://imgur.com/a/5AN8EXl
不要介意 textFields 格式和文本,我可以稍后修复它们。我只想能够对齐 textFields 占位符。
【问题讨论】:
标签: ios swift textfield placeholder