GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - lucatorella/SwiftAutoLayout

BranchesTags
Open more actions menu

Latest commit

 

History

19 Commits
19 Commits

Folders and files

NameName
Last commit message
Last commit date
SwiftAutoLayout.xcodeproj
SwiftAutoLayout.xcodeproj
 
 
SwiftAutoLayout
SwiftAutoLayout
 
 
SwiftAutoLayoutTests
SwiftAutoLayoutTests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

Carthage compatible

SwiftAutoLayout

SwiftAutoLayout is a UIView extension to easily create Auto Layout constraints. Auto Layout is a powerful tool, but it's often very verbose. This extension try to simplify some of the common uses of Auto Layout with some handy methods.

Initialization

There's a factory method to create a UIView with setTranslatesAutoresizingMaskIntoConstraints already set to false.

let myView = UIView.newAutoLayoutView()

Centering

With SwiftAutolayout it's easy to center a view in its superview.

myView.centerInSuperview()

Pin edges

With SwiftAutolayout it's easy to pin view edges to its superview.

myView.pinEdgesToSuperview()
myView.pinEdgesToSuperview(20)

Sizes

With SwiftAutolayout it's easy to create width and height constraints

let size = CGSize(10,10)
myView.constraintSize(size)

With SwiftAutolayout it's easy to match the width of a view to the width of another view?

myView.matchDimension(.Width, otherView: myOtherView)

The complete API

extension UIView {
	// MARK: Factory Methods
	class func newAutoLayoutView() -> UIView

	// MARK: Centering
	func centerInSuperview(autoAdd: Bool = true) -> [NSLayoutConstraint]
	func centerInSuperview(axis: NSLayoutAttribute, autoAdd: Bool = true) -> NSLayoutConstraint

	// MARK: Pin Edges to Superview
	func pinEdgesToSuperview(distance: CGFloat = 0, autoAdd: Bool = true) -> [NSLayoutConstraint]
	  
	// MARK: Same dimension
	func matchDimension(dimension: NSLayoutAttribute, toItem view: UIView, multiplier: CGFloat = 1, constant c: CGFloat = 0, autoAdd: Bool = true) -> NSLayoutConstraint
	func matchWidthWithHeight(multiplier: CGFloat = 1, constant c: CGFloat = 0, autoAdd: Bool = true) -> NSLayoutConstraint

	// MARK: Set size
	func constraintSize(size: CGSize, relatedBy relation: NSLayoutRelation = .Equal, autoAdd: Bool = true) -> [NSLayoutConstraint]
}

extension NSLayoutConstraint {
	convenience init(item view1: AnyObject, attribute attr: NSLayoutAttribute, relatedBy relation: NSLayoutRelation = .Equal, toItem view2: AnyObject?, multiplier: CGFloat = 1, constant c: CGFloat = 0)
	class func constraintsWithVisualFormat(format: String, metrics: [NSObject : AnyObject]?, views: [NSObject : AnyObject]) -> [AnyObject]
	class func constraintsWithVisualFormat(format: String, options opts: NSLayoutFormatOptions, views: [NSObject : AnyObject]) -> [AnyObject]
	class func constraintsWithVisualFormat(format: String, views: [NSObject : AnyObject]) -> [AnyObject]
}

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.