If you write code using Auto Layout, you will have noticed by now that the structure of the code from using NSLayoutConstraint
isn't that readable once you have a few more UI elements.
Cartography by Robb Böhnke changes that by introducing a declarative manner to specify Auto Layout constraints in Swift.
This is an example given in the README:
layout(view1, view2) { view1, view2 in
view1.width == (view1.superview!.width - 50) * 0.5
view2.width == view1.width - 50
view1.height == 40
view2.height == view1.height
view1.centerX == view1.superview!.centerX
view2.centerX == view1.centerX
view1.top >= view1.superview!.top + 20
view2.top == view1.bottom + 20
}
If you are working with Objective C, also look at FLKAutoLayout by Florian Kugler.
.
Here's a few related nuggets:
- iOS Dev Nugget 314 Checked Array Subscripting
- iOS Dev Nugget 310 Weak Reference Wrapper Class
- iOS Dev Nugget 308 Careful with early return statements in functions that return void
- iOS Dev Nugget 307 Array Out of Bounds
- iOS Dev Nugget 306 Underscores in Numeric Literals
- iOS Dev Nugget 305 Declaring Distinct Types from General Types
- iOS Dev Nugget 303 Use Enums for States
- iOS Dev Nugget 302 Realm
- iOS Dev Nugget 301 Print App Document Path II
- iOS Dev Nugget 300 Pipe Operator
- iOS Dev Nugget 295 SwifterSwift
- iOS Dev Nugget 293 iOSSnapshotTestCase (was FBSnapshotTestCase)
- iOS Dev Nugget 292 for-where
- iOS Dev Nugget 291 Implicit Member Expressions
- iOS Dev Nugget 287 Modifying a Property Which is a Struct Triggers didSet
- iOS Dev Nugget 283 Eureka for Forms
- iOS Dev Nugget 281 Use R.swift for Static References to Resources Like Images
- iOS Dev Nugget 280 Using Custom Fonts Without Updating Info.plist Manually
- iOS Dev Nugget 269 Including Finger Touches in App Preview Videos
- iOS Dev Nugget 265 value type cannot have a stored property that recursively contains it
- iOS Dev Nugget 257 Asserts
- iOS Dev Nugget 251 Retrieving the Current View Controller
- iOS Dev Nugget 248 In-app Native Routing
- iOS Dev Nugget 246 Mapping Swift and Obj-C Method Names
- iOS Dev Nugget 244 IteratorProtocol
- iOS Dev Nugget 241 Swift Enums with Labels
- iOS Dev Nugget 240 Print an Object's Unique Identifier
- iOS Dev Nugget 234 #available and @available
- iOS Dev Nugget 229 Promises
- iOS Dev Nugget 228 Recording and Playing Back Network Calls
- iOS Dev Nugget 215 dump Instead of print for Swift Structs
- iOS Dev Nugget 211 Higher Order Functions: map, filter, reduce
- iOS Dev Nugget 210 PMAlertController
- iOS Dev Nugget 209 Swift Defer
- iOS Dev Nugget 207 Swift Nil-Coalescing Operator
- iOS Dev Nugget 206 Date doesRelativeDateFormatting
- iOS Dev Nugget 205 The Never Return Type in Swift
- iOS Dev Nugget 204 Swift @autoclosure
- iOS Dev Nugget 203 Swift Measurement
- iOS Dev Nugget 202 Swift Enumerations to Encode States
- iOS Dev Nugget 201 Swift Pattern Matching
- iOS Dev Nugget 200 Swift flatMap
- iOS Dev Nugget 199 Swift Talk Video Series
- iOS Dev Nugget 198 KZPlayground
- iOS Dev Nugget 197 App Initialization Code
- iOS Dev Nugget 196 Rename Refactoring for Swift Code
- iOS Dev Nugget 193 Result Enumeration
- iOS Dev Nugget 190 Quick Look Plug-in for Mobile Provisioning Files
- iOS Dev Nugget 188 SwiftLint
- iOS Dev Nugget 187 Creating a Singleton Class in Swift
- iOS Dev Nugget 186 Injection for Xcode
- iOS Dev Nugget 184 Async Library
- iOS Dev Nugget 182 Tracking the swift-evolution Git Repository
- iOS Dev Nugget 181 Swift Selectors
- iOS Dev Nugget 180 Low Power Mode
- iOS Dev Nugget 172 Print App Document Path
- iOS Dev Nugget 168 Using Blocks to Manage Contexts
- iOS Dev Nugget 158 Checking if Newer APIs Are Available In Older iOS Versions (II)
- iOS Dev Nugget 151 More Wrappers for Keychain Access
- iOS Dev Nugget 149 Timepiece, a Swift Library for Handling Dates
- iOS Dev Nugget 146 UIStackView and TZStackView
- iOS Dev Nugget 145 Listing Available Fonts
- iOS Dev Nugget 143 Don't Forget SQLite
- iOS Dev Nugget 142 Grand Central Dispatch
- iOS Dev Nugget 141 Great Swift Standard Library Examples Covered in Playground (Swift 2.0)
- iOS Dev Nugget 139 Custom Build Configurations and Xcode Subprojects
- iOS Dev Nugget 138 Interoperability: Using Enumerations Defined In Objective-C from Swift
- iOS Dev Nugget 137 Named Tuple Elements
- iOS Dev Nugget 135 CAShapeLayer, Animated Views and XCPShowView()
- iOS Dev Nugget 133 Dollar.swift
- iOS Dev Nugget 132 XCPCaptureValue in Swift Playgrounds
- iOS Dev Nugget 131 Running Asynchronous Code in Swift Playgrounds
- iOS Dev Nugget 129 Browsing the Swift Standard Library
- iOS Dev Nugget 124 performSelector:withObject:afterDelay: in Swift
- iOS Dev Nugget 123 Using dynamicType in Swift
- iOS Dev Nugget 121 InflectorKit
- iOS Dev Nugget 116 method() is unavailable: use object construction Class()
- iOS Dev Nugget 115 Displaying Information in Settings App
- iOS Dev Nugget 114 Preview an Image for Debugging
- iOS Dev Nugget 113 GPUImage, a GPU-based Image and Video Processing Framework
- iOS Dev Nugget 85 A More Customizable Button For Different States
- iOS Dev Nugget 81 TMCache For In-Memory and Disk-backed Caching
- iOS Dev Nugget 79 TweetBot Photo Flicking Effect
- iOS Dev Nugget 73 Open Source Date Picker from Square
- iOS Dev Nugget 71 Tap
- iOS Dev Nugget 68 Custom URL Schemes Directory
- iOS Dev Nugget 62 Using PDF Instead of PNG Files for Resizable Assets
- iOS Dev Nugget 49 Wrapper to Get UIColor Components
- iOS Dev Nugget 32 FMDB: Thin Objective C Wrapper Around SQLite
- iOS Dev Nugget 1 Easy logging of values and objects
.