[英]Width of UITextField in UITableViewCell
I have a UITextfield in a UITableViewCell.我在 UITableViewCell 中有一个 UITextfield。 I want the width of the UITextfield to be equal to the width of UITableViewCell.
我希望 UITextfield 的宽度等于 UITableViewCell 的宽度。 Refer to screenshot below.
请参阅下面的屏幕截图。
Applying any constraints causes the width to shrink, as seen in the screenshot below.应用任何约束都会导致宽度缩小,如下面的屏幕截图所示。
func configure(text: String, placeholder: String) {
emailTextField.text = text
emailTextField.placeholder = placeholder
emailTextField.accessibilityValue = text
emailTextField.accessibilityLabel = placeholder
emailTextField.autocorrectionType = .no
}
Any advice will be much appreciated.任何建议将不胜感激。
Add Auto Layout Constrains:Leading,Top and Width of the text field should equal to superView width and adjust the Multiplier according to it.添加 Auto Layout Constrains:Leading、Top 和 Width 文本字段应等于 superView 宽度并根据它调整 Multiplier。
Hope it works, sorry if I'm wrong.希望它有效,如果我错了,抱歉。
I have added the two different simulator screenshots for yours reference.我添加了两个不同的模拟器屏幕截图供您参考。
I had a similar problem, and solved it by reducing the horizontal content hugging priority to 249.我有一个类似的问题,并通过将水平内容拥抱优先级降低到 249 来解决它。
https://developer.apple.com/documentation/uikit/uiview/1622485-setcontenthuggingpriority https://krakendev.io/blog/autolayout-magic-like-harry-potter-but-real https://developer.apple.com/documentation/uikit/uiview/1622485-setcontenthuggingpriority https://krakendev.io/blog/autolayout-magic-like-harry-potter-but-real
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.