【发布时间】:2015-12-28 11:07:47
【问题描述】:
我有一个自定义 UITextfield,它通过约束以 x 为中心位于其超级视图。它还在文本下方有一个高度约束和一条漂亮的细线,与文本字段本身具有相同的宽度(就像我说的:自定义)。 我现在想在编辑其内容时保持 UITextfield 居中,并根据其字符串内容调整自身的宽度。
现在发生的是它在编辑时保持其宽度,裁剪其重叠内容。
我的代码有点
// on textfields editing change event
@IBAction func nameFieldEditingChanged(sender: AnyObject) {
// set width of textfield to width of textstring
checkUserNameTextfieldWidth()
}
func checkUserNameTextfieldWidth(){
println("checkUserNameTextfieldWidth \(userName.text) / \(userName.frame.size.width) / \(view.bounds.width)")
// something has to happen here I guess...
}
谢谢!
【问题讨论】:
标签: swift xcode6 uitextfield