TABSwiftLayout

所属分类:硬件设计
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2019-08-15 14:34:48
上 传 者sh-1993
说明:  提供灵活但最小的API,用于以编程方式处理AutoLayout,
(Provides a flexible, yet minimal API for dealing with AutoLayout programatically,)

文件列表:
.travis.yml (216, 2019-01-11)
CHANGELOG.md (1234, 2019-01-11)
LICENSE (1061, 2019-01-11)
Metadata/ (0, 2019-01-11)
Metadata/Info.plist (806, 2019-01-11)
Metadata/TABSwiftLayout.h (541, 2019-01-11)
Sources/ (0, 2019-01-11)
Sources/Deprecations.swift (10557, 2019-01-11)
Sources/Layout.swift (13064, 2019-01-11)
Sources/LayoutDefines.swift (5693, 2019-01-11)
Sources/PlatformDefinitions.swift (641, 2019-01-11)
TABSwiftLayout.podspec (601, 2019-01-11)
TABSwiftLayout.xcodeproj/ (0, 2019-01-11)
TABSwiftLayout.xcodeproj/project.pbxproj (24315, 2019-01-11)
TABSwiftLayout.xcodeproj/project.xcworkspace/ (0, 2019-01-11)
TABSwiftLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata (159, 2019-01-11)
TABSwiftLayout.xcodeproj/project.xcworkspace/xcshareddata/ (0, 2019-01-11)
TABSwiftLayout.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (238, 2019-01-11)
TABSwiftLayout.xcodeproj/xcshareddata/ (0, 2019-01-11)
TABSwiftLayout.xcodeproj/xcshareddata/xcschemes/ (0, 2019-01-11)
TABSwiftLayout.xcodeproj/xcshareddata/xcschemes/TABSwiftLayout.xcscheme (3782, 2019-01-11)
TABSwiftLayoutTests/ (0, 2019-01-11)
TABSwiftLayoutTests/Info.plist (701, 2019-01-11)
TABSwiftLayoutTests/LayoutDefinesTests.swift (3424, 2019-01-11)
TABSwiftLayoutTests/LayoutTests.swift (14704, 2019-01-11)
assets/ (0, 2019-01-11)
assets/logo.png (41486, 2019-01-11)

![The App Business](https://github.com/theappbusiness/TABSwiftLayout/blob/master/assets/logo.png) # TABSwiftLayout [![Build Status](https://github.com/theappbusiness/TABSwiftLayout/blob/master/https://travis-ci.org/theappbusiness/TABSwiftLayout.svg?branch=master)](https://github.com/theappbusiness/TABSwiftLayout/blob/master/https://travis-ci.org/theappbusiness/TABSwiftLayout) [![](https://github.com/theappbusiness/TABSwiftLayout/blob/master/https://img.shields.io/cocoapods/v/TABSwiftLayout.svg)](https://github.com/theappbusiness/TABSwiftLayout/blob/master/https://cocoapods.org/pods/TABSwiftLayout) [![](https://github.com/theappbusiness/TABSwiftLayout/blob/master/https://img.shields.io/cocoapods/p/TABSwiftLayout.svg?style=flat)](https://github.com/theappbusiness/TABSwiftLayout/blob/master/https://cocoapods.org/pods/TABSwiftLayout) ## What does it do? A library for providing a flexible, yet very minimal API for dealing with AutoLayout programatically. ## Why would I use it? Using the standard Apple API is very cumbersome. Even something simple like constraining the width of a view: ```swift let constraint = NSLayoutConstraint(item: view, attribute: .width, relatedBy: .equal, toItem: view, attribute: .width, multiplier: 1, constant: 100) NSLayoutConstraint.activateConstraints([constraint]) ``` Now with SwiftLayout: ```swift view.size(.horizontal, relatedBy: .equal, size: 100) ``` As you can see, SwiftLayout also removes the need for you to activate your constraints, and removes the redundancy required in Apple's API. ## What can I do with it? Currently all the most common layout tasks can be completed with SwiftLayout. Position: ```swift view.pin(edge: .top, toEdge: .top, ofView: view.superview) // default margin 0 view.pin(edge: .top, toEdge: .top, ofView: view.superview, margin: 15) view.pin(edges: [.left, .right], ofView: view.superview) // default margins (0, 0, 0, 0) view.pin(edges: [.left, .right], ofView: view.superview, margins: EdgeMargins(top: 0, left: 15, bottom: 0, right: 15)) ``` Sizing: ```swift view.size(axis: .horizontal, ofViews: [view]) // default ratio 1.0 view.size(axis: .horizontal, ofViews: [view], ratio: 1.5) view.size(axis: .horizontal, relatedBy: .equal, size: 100) view.size(axis: .horizontal, relativeTo: .horizontal, ofView: view.superview) // default ratio 1.0 view.size(axis: .horizontal, relativeTo: .horizontal, ofView: view.superview, ratio: 0.5) ``` Alignment (convenience methods): ``` view.alignTop(toView: otherView) view.alignBottom(toView: otherView) view.alignLeft(toView: otherView) view.alignRight(toView: otherView) view.alignHorizontally(toView: otherView) view.alignVertically(toView: otherView) ``` ## Caveats As with Apple's API, you MUST ensure your view has been added to a superview BEFORE setting any constraints on it. However with SwiftLayout, the constraints will NOT be added in this case, and a nice print() message will indicate that you've made a mistake. ## Additional API SwiftLayout also includes an additional set of API for inspecting the types of constraints currently applied to a view. ```swift let constraints = view.viewConstraints ``` This API differs slightly from Apple's implementation, since it will return automatically scan through the superview as well, in order to return ALL constraints currently being applied to this view. ```swift let constraints = view.constraints(forTrait: .leftMargin) ``` This is extremely useful when you need to adjust the constant or replace a specific constraint entirely. Even better, its a bit mask, so you can request multiple constraints at once ;) ```swift if view.contains(trait: [.leftMargin, .rightMargin]) { ... } ``` Finally, you can also inspect a view, to determine if it contains a specific set of layout traits.

近期下载者

相关文件


收藏者