作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我的项目中有一个分段控件。我想隐藏并自动布局我的按钮。但是如果我只是隐藏文本字段并在分段控件下标记按钮,问题仍然不会移动。所以之间有一个空格我的分段控件和下一个按钮。如果我在分段控件上单击“否”,我想将下一个按钮向上移动。
-如果我在分段控制上单击"is"分段控件下的下一个按钮将限制我的文本字段并显示分段控件下的所有文本字段和标签
-如果我在分段控制上单击“否”分段控件下的下一个按钮将约束到我的分段控件并隐藏分段控件下的所有文本字段和标签
谢谢大家的回答
最佳答案
有关如何根据分段开关更改按钮位置的快速示例。
下图显示使用 socket 并且类型需要为 NSLayoutConstraint
在 ViewController.Swift 中,代码应如下所示。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var switchControl: UISegmentedControl!
@IBOutlet weak var heighConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func switchPressed(_ sender: Any) {
switch switchControl.selectedSegmentIndex
{
case 0:
// here you can see the constant is being set, this will determine the
// position of your button. You will need to set the correct position.
heighConstraint.constant = 150
case 1:
heighConstraint.constant = 200
default:
break;
}
}
}
希望这个答案有帮助。
关于swift - 如何在 swift 中隐藏文本字段并自动布局约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51186857/
我是一名优秀的程序员,十分优秀!