如何以特定距离进行编程设置约束?

发布于 2025-02-06 23:23:21 字数 398 浏览 2 评论 0原文

我的布局中有一个按钮,我想专门将其设置为safearea.bottom = button.bottom + 28。我尝试使用时会出现错误,

btnAddRecord.translatesAutoresizingMaskIntoConstraints = false
btnAddRecord.bottomAnchor.constraint.equalTo(self.view.safeAreaLayoutGuide.bottomAnchor, constant: 66).isActive = true

我会遇到错误的“参考'forem'qualiento'上下文类型'

我可以知道我在哪里出错以及如何解决这个问题吗?谢谢!

I have a button in my layout and I would like to specifically set it to SafeArea.bottom = button.bottom + 28. I am having errors when I try using

btnAddRecord.translatesAutoresizingMaskIntoConstraints = false
btnAddRecord.bottomAnchor.constraint.equalTo(self.view.safeAreaLayoutGuide.bottomAnchor, constant: 66).isActive = true

I am getting an error 'Reference to member 'equalTo' cannot be resolved without a contextual type'

May I know where I am going wrong and how to fix this issue? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当梦初醒 2025-02-13 23:23:21

语法是错误的,请尝试以下操作:

 btnAddRecord.translatesAutoresizingMaskIntoConstraints = false
 btnAddRecord.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -28).isActive = true

view.bottomanchor请参阅Supperiew而非SafeArea,将其相对于安全区域设置,您需要这样做:

 btn.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor, constant: -28).isActive = true

28负会将其放在安全区域之上。

The syntax is wrong, Try This :

 btnAddRecord.translatesAutoresizingMaskIntoConstraints = false
 btnAddRecord.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -28).isActive = true

Also view.bottomAnchor refer to superview and not safeArea , for setting it relative to safe area , you need to do like this :

 btn.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor, constant: -28).isActive = true

28 negative will put it above the safe area.

霓裳挽歌倾城醉 2025-02-13 23:23:21

TranslatesAutoresizingMaskIntocontaints需要将其设置为false。

代码是:

yourButton.translatesAutoresizingMaskIntoConstraints = false
yourButton.bottomAnchor.constraint.equalTo(constraint: view.bottom, constant: 28)

translatesAutoresizingMaskIntoConstraints needs to be set as false.

Code Be like:

yourButton.translatesAutoresizingMaskIntoConstraints = false
yourButton.bottomAnchor.constraint.equalTo(constraint: view.bottom, constant: 28)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文