【发布时间】:2017-02-16 05:51:54
【问题描述】:
我有UITextFields 列表,其中包含基于UILabel 之后的选项需要显示的下拉菜单。
UITextField
DropdownMenu
UITextField
UITextField
如上所述,它的显示启动应用程序。更改下拉菜单后需要显示标签。
UITextField
DropdownMenu
UILabel
UITextField
UITextField
我知道如何使用label.hidden = true 隐藏UILabel。但是隐藏之后,UILabel 还是占据了空间。之后只显示两个UITextField。如果有任何方法可以在隐藏标签后动态更改位置。
我以编程方式使用了创建文本字段和标签:
let textField1 = UITextField(frame: CGRect(x: 20, y: 10, width: UIApplication.shared.statusBarFrame.size.width - 40, height:45))
let textField2 = UITextField(frame: CGRect(x: 20, y: textField1.frame.origin.y + textField1.frame.size.height + 10, width: UIApplication.shared.statusBarFrame.size.width - 40, height: 45))
let button = UIButton(frame: CGRect(x: 20, y: textField2.frame.origin.y + textField2.frame.size.height + 10, width: UIApplication.shared.statusBarFrame.size.width - 40, height: 45))
let label1 = UILabel(frame: CGRect(x: 20, y: button.frame.origin.y + button.frame.size.height + 10, width: UIApplication.shared.statusBarFrame.size.width - 40, height: 45))
let textField3 = UITextField(frame: CGRect(x: 20, y: label1.frame.origin.y + label1.frame.size.height + 10, width: UIApplication.shared.statusBarFrame.size.width - 40, height: 45))
let textField4 = UITextField(frame: CGRect(x: 20, y: textField3.frame.origin.y + textField3.frame.size.height + 10, width: UIApplication.shared.statusBarFrame.size.width - 40, height: 45))
【问题讨论】:
-
您使用的是自动布局还是自动调整大小
-
仅使用自动布局@Anbu.Karthik
-
以编程方式或在情节提要中使用自动布局?你能把你的代码贴在这里吗?
-
使用
UIStackView -
@vara 我猜你需要这个stackoverflow.com/questions/31904573/…
标签: ios swift user-interface