explaingit

gsdios/sdautolayout

5,873Objective-CAudience · developerComplexity · 2/5Setup · easy

TLDR

SDAutoLayout is an Objective-C library for iOS that lets you write Auto Layout constraints in a compact chainable dot-notation style, replacing Apple's verbose raw API calls with single-expression view positioning.

Mindmap

mindmap
  root((repo))
    What It Does
      Simplifies Auto Layout
      Chainable dot notation
      One-line positioning
    Key Features
      Fixed value constraints
      Ratio to parent
      Spacing to view
      Dynamic cell height
      Label auto height
      ScrollView sizing
    Installation
      CocoaPods
    Tech Stack
      Objective-C
      iOS runtime
    Use Cases
      Table cell height
      Dynamic labels
      Scroll content size
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace verbose NSLayoutConstraint code with compact chainable expressions for positioning iOS views

USE CASE 2

Automatically calculate and cache dynamic UITableViewCell heights based on their content

USE CASE 3

Make a UILabel resize its height to fit its text with a single method call

USE CASE 4

Adapt UIScrollView content size automatically based on the layout of its subviews

Tech stack

Objective-CCocoaPodsiOS

Getting it running

Difficulty · easy Time to first run · 30min

Installed via CocoaPods, requires Xcode and an iOS development environment.

In plain English

SDAutoLayout is an Objective-C library for iOS that simplifies the process of positioning and sizing interface elements. In iOS development, Auto Layout is the system Apple provides for describing how views should arrange themselves relative to each other and to the screen. Writing these layout rules in raw Apple API calls tends to be verbose. SDAutoLayout replaces those calls with a chainable dot-notation style, so you can express the layout rules for a single view in one compact sequence of method calls. For example, you can place a view 10 points from the left of its parent, 80 points from the top, set a fixed height, and set its width as a proportion of its parent, all in a single chained expression. Methods follow a consistent naming pattern: those with SpaceToView accept a reference view and a distance, those with RatioToView accept a reference view and a multiplier, and those with Is accept a fixed value. The library also handles two situations that are otherwise tedious in iOS. First, table view cells whose height depends on their content: you call one method after setting up the cell layout and a second method in the table delegate to get the calculated value, with caching built in for performance. Second, labels whose height should adjust to fit the amount of text they display: one method call enables this. ScrollView content size adaptation is also supported, both vertically and horizontally. The library is available through CocoaPods for easy installation and is built on top of the Objective-C runtime. The README is primarily in Chinese and includes animated GIF demos, a changelog going back to 2015, links to video tutorials, and a reference to a complete WeChat-style demo app that shows the library used in a realistic project.

Copy-paste prompts

Prompt 1
Using SDAutoLayout, write Objective-C code to position a UIView 10 points from the left and 80 points from the top of its parent container, with a fixed height and a width that is half the parent's width.
Prompt 2
Show me how to configure a UITableViewCell with SDAutoLayout so its row height adjusts automatically to the amount of content inside it.
Prompt 3
Write Objective-C code using SDAutoLayout to make a UILabel grow taller to fit whatever text is assigned to it at runtime.
Prompt 4
How do I install SDAutoLayout with CocoaPods and use it to make a UIScrollView automatically size its content area to fit all its subviews?
Open on GitHub → Explain another repo

← gsdios on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.