ios - Xcode 7.3 中的自动布局 (swift 2)

标签 ios xcode swift view autolayout

我在 YouTube、指南、常见问题解答等中观看了很多视频,因此我可以使用自动布局创建 View ,但现在,我有一个项目,具有带有动态加载元素的硬 UI 结构和许多像这样的不同观点:
(草图 3 屏幕)

是否有任何框架或方法可以让我的工作更轻松?

Sketch 3 screen

最佳答案

有一篇很棒的文章可以更深入地学习它: https://www.objc.io/issues/3-views/advanced-auto-layout-toolbox/

反正有一套自动布局工具可以让日常使用变得简单:

砌体 ( https://github.com/SnapKit/Masonry )

//these two constraints are exactly the same
make.left.greaterThanOrEqualTo(label);
make.left.greaterThanOrEqualTo(label.mas_left);


//creates view.left = view.superview.left + 10
make.left.lessThanOrEqualTo(@10)

EasyPeasy ( https://github.com/nakiostudio/EasyPeasy )

    // Apply width = 0 and height = 0 constraints
       view <- Size()

    // Apply width = referenceView.width and height = referenceView.height constraints
       view <- Size().like(referenceView)

    // Apply width = 100 and height = 100 constraints
       view <- Size(100)

    // Apply width = 200 and height = 100 constraints
       view <- Size(CGSize(width: 200, height: 100)


    // Apply left = 0, right = 0, top = 0 and bottom = 0 constraints to its superview
       view <- Edges()

    // Apply left = 10, right = 10, top = 10 and bottom = 10 constraints to its superview
       view <- Edges(10)

    // Apply left = 10, right = 10, top = 5 and bottom = 5 constraints to its superview
       view <- Edges(UIEdgeInsets(top: 5, left: 10, bottom: 5, right: 10))

纯布局(https://github.com/PureLayout/PureLayout)

//returns the constraints it creates so you have full control:
let constraint = skinnyView.autoMatchDimension(.Height, toDimension: .Width, ofView: tallView)

// 2 constraints created & activated in one line!
logoImageView.autoCenterInSuperview()

// 4 constraints created & activated in one line!
textContentView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 20.0, left: 5.0, bottom: 10.0, right: 5.0))

关于ios - Xcode 7.3 中的自动布局 (swift 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37033728/

相关文章:

iOS (Swift) 应用程序在 JSON 解析时崩溃

android - 我可以在 Nativescript 标签或 Textview 中使用富文本吗

ios - 如何在 2 个不同的 UICollectionViewFlowLayout 实例之间切换?

xcode - 如何在 UITextView 返回/搜索键上添加一个 Action ?(swift 2)

ios - 如何修复 C 风格的语句?

javascript - iOS Phonegap 使用手势滑动检测

ios - XCode 6 CocoaPods 错误 : target overrides the `OTHER_LDFLAGS` build setting

iphone - 如何写入AppName-Info.plist

初始化时 Swift 触发 didSet

ios - 将代码更新为 Swift 3