All Projects → jdisho → VanillaConstraints

jdisho / VanillaConstraints

Licence: MIT license
🍦 Simplified and chainable AutoLayout constraints for iOS.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to VanillaConstraints

Core Layout
Flexbox & CSS-style Layout in Swift.
Stars: ✭ 215 (+411.9%)
Mutual labels:  layout, constraints, autolayout
Kvconstraintkit
An Impressive Auto Layout DSL for iOS, tvOS & OSX. & It is written in pure swift.
Stars: ✭ 91 (+116.67%)
Mutual labels:  layout, constraints, autolayout
Easyswiftlayout
Lightweight Swift framework for Apple's Auto-Layout
Stars: ✭ 345 (+721.43%)
Mutual labels:  layout, constraints, autolayout
Uicollectionview Layouts Kit
📐 A set of custom layouts for UICollectionView with examples [Swift 5.3, iOS 12].
Stars: ✭ 410 (+876.19%)
Mutual labels:  layout, constraints, autolayout
wwlayout
Swifty DSL for programmatic Auto Layout in iOS
Stars: ✭ 46 (+9.52%)
Mutual labels:  layout, constraints, autolayout
Stevia
🍃 Concise Autolayout code
Stars: ✭ 3,182 (+7476.19%)
Mutual labels:  layout, constraints, autolayout
Snapkit
A Swift Autolayout DSL for iOS & OS X
Stars: ✭ 18,091 (+42973.81%)
Mutual labels:  layout, constraints, autolayout
EZAnchor
An easier and faster way to code Autolayout
Stars: ✭ 25 (-40.48%)
Mutual labels:  layout, constraints, autolayout
Mylinearlayout
MyLayout is a powerful iOS UI framework implemented by Objective-C. It integrates the functions with Android Layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,PathLayout,GridLayout,LayoutSizeClass to build your App 自动布局 UIView UITab…
Stars: ✭ 4,152 (+9785.71%)
Mutual labels:  layout, constraints, autolayout
Tinyconstraints
Nothing but sugar.
Stars: ✭ 3,721 (+8759.52%)
Mutual labels:  layout, constraints
Nerdyui
An easy way to create and layout UI components for iOS.
Stars: ✭ 381 (+807.14%)
Mutual labels:  layout, constraints
Autoinch
优雅的iPhone全尺寸/等比例精准适配工具
Stars: ✭ 395 (+840.48%)
Mutual labels:  layout, autolayout
Cupcake
An easy way to create and layout UI components for iOS (Swift version).
Stars: ✭ 273 (+550%)
Mutual labels:  layout, constraints
Keyboardlayoutguide
⌨️ Manage iOS keyboard with Apple's missing KeyboardLayoutGuide
Stars: ✭ 1,054 (+2409.52%)
Mutual labels:  layout, autolayout
Framelayoutkit
FrameLayoutKit is a super fast and easy to use autolayout kit
Stars: ✭ 53 (+26.19%)
Mutual labels:  layout, autolayout
Layoutframeworkbenchmark
Benchmark the performances of various Swift layout frameworks (autolayout, UIStackView, PinLayout, LayoutKit, FlexLayout, Yoga, ...)
Stars: ✭ 316 (+652.38%)
Mutual labels:  layout, autolayout
Easypeasy
Auto Layout made easy
Stars: ✭ 1,877 (+4369.05%)
Mutual labels:  layout, constraints
Flexlib
FlexLib是一个基于flexbox模型,使用xml文件进行界面布局的框架,融合了web快速布局的能力,让iOS界面开发像写网页一样简单快速
Stars: ✭ 1,569 (+3635.71%)
Mutual labels:  layout, autolayout
SuperPuperDuperLayout
Super puper duper mega easy awesome wrapper over auto layout!!111!!1!!!1!!!11111!!!1!!
Stars: ✭ 14 (-66.67%)
Mutual labels:  layout, constraints
Snapkitextend
SnapKit的扩展,SnapKit类似于Masonry,但是其没有对Arry的设置和对等间距排列的布局等,此扩展是类似Masonry的写法对SnapKit的补充,同时补充九宫格布局方式
Stars: ✭ 110 (+161.9%)
Mutual labels:  layout, constraints

🍦 VanillaConstraints

Twitter: @_disho

  • A simplified and chainable AutoLayout for iOS written in Swift.
  • A thin wrapper around NSLayoutConstraints.
  • Short syntax for creating layout constraints.
  • Chainable way of describing NSLayoutConstraints.
  • Using KeyPaths.
  • Constraints are active by default.
  • No need to set translatesAutoresizingMaskIntoConstraints = false.
  • No external dependencies.

🛠 Installation

CocoaPods

To integrate VanillaConstraints into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'VanillaConstraints'

Then, run the following command:

$ pod install

Carthage

github "jdisho/VanillaConstraints" ~> 1.0

Then, run the following command:

$ carthage update

Manually

If you prefer not to use any of the dependency managers, you can integrate VanillaConstraints into your project manually, by downloading the source code and placing the files on your project directory.

👨🏻‍💻 Usage

tl;dr

It allows you to replace this:

anotherView.addSubview(view)

view.translatesAutoresizingMaskIntoConstraints = false

let top = view.topAnchor.constraint(equalTo: anotherView.topAnchor, constant: 16.0)
top.priority = .defaultLow
top.isActive = true

let trailing = view.trailingAnchor.constraint(lessThanOrEqualTo: anotherView.trailingAnchor)
trailing.priority = .defaultHigh
trailing.isActive = true

let bottom = view.bottomAnchor.constraint(equalTo: anotherView.bottomAnchor, constant: 16.0)
bottom.priority = .required
bottom.isActive = true

let leading = view.leadingAnchor.constraint(greaterThanOrEqualTo: anotherView.leadingAnchor, constant: 8.0)
leading.isActive = true

with this:

view.add(to: anotherView)
  .top(to: \.topAnchor, constant: 16.0, priority: .defaultLow)
  .trailing(to: \.trailingAnchor, relation: .equalOrLess, priority: .defaultHigh)
  .bottom(to: \.bottomAnchor, constant: 16.0)
  .leading(to: \.leadingAnchor, relation: .equalOrGreater, constant: 8.0)

⚠️ If the anchor's view is not specified, it is constrained where it is added.

Edges

Pin a view to the edges of another view:

anotherView.addSubview(view)

view.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
    view.topAnchor.constraint(equalTo: anotherView.topAnchor),
    view.leadingAnchor.constraint(equalTo: anotherView.leadingAnchor),
    view.bottomAnchor.constraint(equalTo: anotherView.bottomAnchor),
    view.trailingAnchor.constraint(equalTo: anotherView.trailingAnchor)
])

with VanillaConstraints:

view.add(to: anotherView).pinToEdges()

or with equal margins:

view.add(to: anotherView).pinToEdges(withMargins: 16.0)

or pinned to some other view different from where it is added:

view.add(to: anotherView).pinToEdges(of: someOtherView)

or pinned to safeAreaLayoutGuide egdes:

view.add(to: anotherView).pinToEdges(safeConstrainable: true) // false by default

Center

Center a view to another view:

anotherView.addSubview(view)

view.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
    view.centerXAnchor.constraint(equalTo: anotherView.centerXAnchor)
    view.centerYAnchor.constraint(equalTo: anotherView.centerYAnchor)
])

with VanillaConstraints:

view.add(to: anotherView).center()

or centered in some other view different from where it is added:

view.add(to: anotherView).center(in: someOtherView)

Size

Set the size of the view:

anotherView.addSubview(view)

view.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
    view.widthAnchor.constraint(equalToConstant: 50.0)
    view.heightAnchor.constraint(equalToConstant: 50.0)
])

with VanillaConstraints:

view.add(to: anotherView).size(CGSize(width: 50.0, height: 50))

or with other relations:

view.add(to: anotherView).size(CGSize(width: 50.0, height: 50), relation: .equalOrLess) // .equal by default 

Supported attributes

  • top
  • bottom
  • left
  • right
  • leading
  • trailing
  • centerX
  • centerY
  • width
  • height

👤 Author

This tiny library is created with ❤️ by Joan Disho

📃 License

VanillaConstraints is released under an MIT license. See License.md for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].