gpt4 book ai didi

ios - 分段控制的编程约束不起作用

转载 作者:行者123 更新时间:2023-11-28 23:58:23 24 4
gpt4 key购买 nike

我正在尝试使用 UIKit 编程约束来创建一个简单的界面,其中一行的左侧是 UISegmentedControl,右侧是黄色的 UIView。

问题是我希望 UIView 扩展到 View 的整个高度,但是由于某种原因它的底部 anchor 不在段 Controller 的实际底部。

enter image description here

这是代码

parentGuide = top.layoutMarginsGuide

let choices = UISegmentedControl(items: ["Op1", "Op2"])
choices.translatesAutoresizingMaskIntoConstraints = false
top.addSubview(choices)
choices.leadingAnchor.constraint(equalTo: parentGuide.leadingAnchor).isActive = true
choices.topAnchor.constraint(equalTo: parentGuide.topAnchor).isActive = true

let yellow = UIView()
yellow.translatesAutoresizingMaskIntoConstraints = false
top.addSubview(yellow)
yellow.backgroundColor = UIColor.yellow
yellow.trailingAnchor.constraint(equalTo: parentGuide.trailingAnchor).isActive = true
yellow.topAnchor.constraint(equalTo: parentGuide.topAnchor).isActive = true
yellow.leadingAnchor.constraint(equalTo: parentGuide.trailingAnchor, constant: -40).isActive = true
yellow.bottomAnchor.constraint(equalTo: choices.layoutMarginsGuide.bottomAnchor).isActive = true

为什么会发生这种情况,我该如何解决?

最佳答案

代替

yellow.bottomAnchor.constraint(equalTo: choices.layoutMarginsGuide.bottomAnchor).isActive = true

成功了

yellow.bottomAnchor.constraint(equalTo: choices.bottomAnchor).isActive = true

关于ios - 分段控制的编程约束不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50440281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com