问题遇到的现象和发生背景
在自定义的Alert上面添加了如下输入框,设置了高度为60
问题相关代码,请勿粘贴截图
// descriptionField
var descriptionField: UITextField = {
let textField = UITextField(frame: .zero)
let typeAttributes: [NSAttributedString.Key : Any] = [
.foregroundColor : UIColor.white,
.font : Theme.Font.PingFangMedium(15.0)
]
textField.defaultTextAttributes = typeAttributes
textField.typingAttributes = typeAttributes
textField.keyboardType = .default
textField.keyboardAppearance = .dark
textField.returnKeyType = .done
textField.textAlignment = .left
textField.contentVerticalAlignment = .top
let str = NSAttributedString(string: "描述",
attributes: [
NSAttributedString.Key.font: Theme.Font.PingFangMedium(15.0),
NSAttributedString.Key.foregroundColor:"#707070".hexColor])
textField.attributedPlaceholder = str
return textField
}()
descriptionField.snp.makeConstraints { make in
make.left.equalTo(descriptionBgView.snp.left).offset(19.75)
make.top.equalTo(descriptionBgView.snp.top).offset(9.42)
make.width.equalTo(Theme.Size.width - 60.0)
make.height.equalTo(60.0)
}
descriptionBgView.addSubview(descriptionField)
运行结果及报错内容
当输入内容超出预定宽度时,输入内容仍然继续向后。检查发现_UITextLayoutFragmentView的高度只有一行文字高度。UITextField,UIFieldEditor,_UITextLayoutCanvasView的高度均为60
我想要达到的结果
UITextField的高度为60,宽度为屏幕宽度-60.输入内容超出设定宽度后,自动换行输入