TinyConstraints Documentation

repository·master·Indexed 26 days ago

https://github.com/roberthein/tinyconstraints

A Swift library providing syntactic sugar for Auto Layout to make constraint creation shorter and more readable. Features include shorthand for edge and center constraints, a stack method for grouping views, and constraints that are active by default.

Tokens
752
Snippets
5
Records
8
Agent score
38%

What's inside TinyConstraints

  1. Install TinyConstraints

    master

    You can install TinyConstraints using CocoaPods, Carthage, or Swift Package Manager.

    ### CocoaPods
    ```ruby
    pod "TinyConstraints"

    Carthage

    github "roberthein/TinyConstraints"

    Swift Package Manager

    Add the following repository URL in Xcode:

    https://github.com/roberthein/TinyConstraints.git
  2. Animate constraint constants

    master

    To animate a constraint, store the constraint object and update its .constant property within a layout animation block.

    let height = view.height(100)
    
    // Animate change
    height.constant = 200
    UIViewPropertyAnimator(duration: 1, dampingRatio: 0.4) {
        self.layoutIfNeeded()
    }.startAnimation()
  3. Store, activate, and deactivate constraints

    master

    Constraints are active by default. To create inactive constraints that you can manage later, set isActive: false. You can then use .activate() or .deActivate() on a Constraints object.

    // Create inactive constraints
    let constraints = view.size(CGSize(width: 100, height: 100), isActive: false)
    
    // Activate them later
    constraints.activate()
    
    // Deactivate and activate in an animation
    oldConstraints.deActivate()
    constraints.activate()
    UIViewPropertyAnimator(duration: 1, dampingRatio: 0.4) {
        self.layoutIfNeeded()
    }.startAnimation()