Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UILabel防止UIButton显示,直到您从调试视图层次结构继续_Ios_Swift_Xcode - Fatal编程技术网

Ios UILabel防止UIButton显示,直到您从调试视图层次结构继续

Ios UILabel防止UIButton显示,直到您从调试视图层次结构继续,ios,swift,xcode,Ios,Swift,Xcode,我有一个包含3个排列子视图的堆栈视图;带有复选框图像的按钮、带有一些文本的标签和带有“i”图像的另一个按钮。创建视图时,由于某种原因,最后一个按钮没有显示,因此我转到“调试视图层次结构”,在该层次结构中,我可以在视图列表中看到该按钮,但在实际视图中看不到该按钮。然后,当我按continue停止调试视图层次结构时,按钮突然出现,并稍微挤压标签使其适合 如果我移除标签,两个按钮都显示得很好。如果我将视图放在UIView而不是堆栈视图中,则不会显示“I”按钮。如果缩短标签上的文字,则“I”按钮将正确显

我有一个包含3个排列子视图的堆栈视图;带有复选框图像的按钮、带有一些文本的标签和带有“i”图像的另一个按钮。创建视图时,由于某种原因,最后一个按钮没有显示,因此我转到“调试视图层次结构”,在该层次结构中,我可以在视图列表中看到该按钮,但在实际视图中看不到该按钮。然后,当我按continue停止调试视图层次结构时,按钮突然出现,并稍微挤压标签使其适合

如果我移除标签,两个按钮都显示得很好。如果我将视图放在UIView而不是堆栈视图中,则不会显示“I”按钮。如果缩短标签上的文字,则“I”按钮将正确显示。编辑:我还尝试切换标签和“I”按钮,然后两者都正确显示

您知道在继续调试时会调用哪些方法来更改视图吗?你知道解决这个问题的另一种方法吗

谢谢

编辑:StackView约束只是带有一些插入常量的SuperView约束:

NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 12),
        stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 12),
        stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10),
        stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 10)
])

按钮和标签只是作为排列的子视图添加的,没有添加任何约束

选择堆栈视图转到属性检查器检查是否对齐=填充和分布=填充现在选择堆栈视图内的标签转到大小检查器查找内容拥抱优先级和内容压缩阻力优先级水平优先级小于250,以便标签可以轻松拉伸和压回

更新:

我添加了两个按钮和一个标签,我只是在按钮中使用文本和颜色来模拟您需要的内容

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let label = UILabel()
    let checkmarkButton = UIButton()
    let infoButton = UIButton()

    label.text = "Jeg acceptere vilkår og betinging"
    label.setContentHuggingPriority(240.0, for: .horizontal)
    label.setContentCompressionResistancePriority(240, for: .horizontal)
    label.textAlignment = .center


    checkmarkButton.setTitle("Check", for: .normal)
    checkmarkButton.backgroundColor = UIColor.blue

    infoButton.setTitle("info", for: .normal)
    infoButton.backgroundColor = UIColor.gray


    view.addSubview(label)
    view.addSubview(checkmarkButton)
    view.addSubview(infoButton)



    let stackView = UIStackView(arrangedSubviews: [checkmarkButton, label, infoButton])
    stackView.translatesAutoresizingMaskIntoConstraints = false
    stackView.axis = .horizontal
    stackView.alignment = .fill
    stackView.distribution = .fill




    view.addSubview(stackView)

    // You have set the trailing constant to 12 which is going outside of the screen if you want to set the trailingAnchor constant programmatically it should be negative
    NSLayoutConstraint.activate([
        stackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 80),
        stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -12),
        stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 12)
        ])

}

在情节提要中,将堆栈视图分布属性设置为均匀填充。。并将标签自动收缩属性设置为最小字体大小等..11请与堆栈视图上/中的约束共享屏幕截图(如果有)编辑以显示约束为什么堆栈视图有底部约束?如果按钮很小,则让stackView自行决定其高度。您是否在后台线程上设置此视图以实例化元素、添加元素、设置约束等?这可能就是为什么您会看到让代码运行和通过调试中断代码之间的区别。可能会显示您正在使用的完整代码?我正在以编程方式工作,但我尝试按照您的建议设置所有代码,但没有改变任何内容,谢谢您的建议。您对stackView有适当的约束吗?啊,第一次我错过了SetContentCompressionResistance优先级,这就造成了差异,非常感谢!!