简体   繁体   English

如何使SnapKit约束左右边缘?

[英]How can I make SnapKit constrain the left and right edges?

Right now if I want to set the margin equally on the left and right side, it requires two lines: 现在,如果我想在左右两侧平均设置边距,则需要两行:

label.snp.makeConstraints { make in
    make.left.equalTo(Constants.margin)
    make.right.equalTo(-Constants.margin)
}

The API also allows me to set all 4 (left/right/top/bottom) edges at once using: 该API还允许我使用以下命令一次设置所有4个(左/右/上/下)边缘:

label.snp.makeConstraints { make in
    make.edges.equalTo(Constants.margin
}

How can I write an extension that will allow something like this? 我如何编写一个允许这样的扩展?

label.snp.makeConstraints { make in
    make.horizontalMargins.equalTo(Constants.margin)
}

The result should equate to the first code snippet. 结果应等于第一个代码段。

label.snp.makeConstraints { make in
    make.left.right.equalToSuperview().inset(Constants.margin)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 锁定在左右边缘的视图可能会随着高度的变化而变化……我该如何加以约束? - A view locked on the left and right edges that can vary in height… how do I constrain that? 如何使用SnapKit实现此目的? - How can I use SnapKit achieve this? 如何从左到右进行程序化的搜索过渡? - How can I make a programmatic segue transition from left to right? 如何制作可在iOS中左右自动移动的滑块? - How can I make a slider that automatically moves left to right in iOS? 如何以编程方式将此背景限制在屏幕边缘 - How do I constrain this background to the edges of the screen programmatically 如何限制导航按钮一直向左或向右? (iOS) - How to constrain navigation buttons all the way to the left or right? (iOS) 如何将 SKShapeNode 约束到 SpriteKit 中的设备边缘? - How do I constrain an SKShapeNode to the device edges in SpriteKit? 我如何通过Swift 3通过snapkit将动画添加到任何UI? - how i can add animation to any UI by snapkit by swift 3? Snapkit:如何在 scrollView 中嵌入一个简单的 tableView? - Snapkit: How can I embed a simple tableView inside a scrollView? iOS开发:如何使视图向右过渡而不是默认向左过渡? - iOS Development: How can I make my view transition to the right instead of to the default left?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM