Git Product home page Git Product logo

vdpin's Introduction

VDPin

CI Status Version License Platform

Description

This repository provides some convenience methods for creating constraints.

Usage

  1. Pin attributes of the view to a specified item or its superview.
view.pin(.edges)
view.pin(.leading)
view.pin(.edges(.horizontal), 16)
view.pin(edges(.top, .bottom), 10, to: safeAreaLayoutGuide)
view.pin(edges: [.top: 10, .horizontal: 5], to: safeAreaLayoutGuide)
// pin view after/before another view
rightView.pin(to: .trailing, of: leftView, options: .offset(10))
view.pin(.center, 10)
view.pin([.size: 100, .centerY: 10, .top: 20, .edges(.horizontal): 10])
  1. Pin any attributes between two views
view.pin(.top, to: .centerY, of: anotherView)
  1. Set aspect ratio of the view.
view.pin(aspectRatio: 2 / 3)
  1. All pin methods contain a with options parameter.
view.pin(.edges, 10, options: .priority(.required))

options:

  • .priority(300): set the priority of the constraint
  • .offset(10): set the offset of the constraint
  • .multiplier(2): set the multiplier of the constraint
  • .relation(.greaterThanOrEqual), .greaterThanOrEqual, .lessThanOrEqual: set the relation of the constraint
  • .inactive, .activated(false): set the active state of the constraint
  • .update: update the constraint if it already exists
  • .translatesAutoresizingMask: don't change translatesAutoresizingMaskIntoConstraints property
  • .safeArea: use safeAreaLayoutGuide instead of superview as default second item
  1. All these methods can be chained
view
    .pin(.edges(.horizontal), 10)
    .pin(to: .bottom, of: anotherView.pin(.height, 50), options: .offset(20))
    .pin(.size, 100)
  1. Use PartialRangeThrough and PartialRangeFrom for offset value
view.pin(.bottom, 10..., with: .safeArea)
view.pin(to: .bottom, of: anotherView, options: .offset(...10))
  1. All these methods return Constraints object, that can be used for updating constraints.

Installation

  1. Swift Package Manager

Create a Package.swift file.

// swift-tools-version:5.7
import PackageDescription

let package = Package(
  name: "SomeProject",
  dependencies: [
    .package(url: "https://github.com/dankinsoid/VDPin.git", from: "1.7.0")
  ],
  targets: [
    .target(name: "SomeProject", dependencies: ["VDPin"])
  ]
)
$ swift build
  1. CocoaPods

Add the following line to your Podfile:

pod 'VDPin'

and run pod update from the podfile directory first.

Author

dankinsoid, [email protected]

License

VDPin is available under the MIT license. See the LICENSE file for more info.

vdpin's People

Contributors

dankinsoid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.