Coder Social home page Coder Social logo

magi82 / mgrelativekit Goto Github PK

View Code? Open in Web Editor NEW
61.0 4.0 3.0 153 KB

Convert absolute to relative layout without autolayout.

Home Page: https://magi82.github.io

License: MIT License

Swift 94.19% Ruby 2.95% Objective-C 2.86%
swift relative layout

mgrelativekit's Introduction

MGRelativeKit

Swift Platform Version Carthage compatible CI Status License

Simple and easy API that converts absolute to relative layout without autolayout. โ˜€๏ธ

MGRelativekit uses the method chaining pattern to add view layouts.
It is recommended to use the 'apply' method for perfomance.

Usage Examples

  • Example 1
view1.relativeLayout
  .size(width: 100, height: 100)
  .centerHorizontalSuper()
  .alignSuperTop(padding: 100)
  .apply()

view2.relativeLayout
  .size(width: 100, height: 100)
  .alignSuperRight(padding: 40)
  .alignSuperBottom(padding: 40)
  .apply()

  • Example 2
view1.relativeLayout
  .size(width: 100, height: 100)
  .centerInSuper()
  .apply()

view2.relativeLayout
  .sizeOf(from: view1)
  .topOf(from: view1)
  .alignLeft(from: view1, padding: 30)
  .apply()

  • Example 3
view1.relativeLayout
  .size(width: 200, height: 200)
  .centerInSuper()
  .apply()

view2.relativeLayout
  .sizeOf(from: view1, margin: -100)
  .centerOf(from: view1)
  .apply()

API Reference

// ---------------------------------------------------------------------------

// Position the current view to the left of the relative view.
func leftOf(from: UIView, margin: CGFloat = 0)

// Position the current view to the right of the relative view.
func rightOf(from: UIView, margin: CGFloat = 0)

// Position the current view to the top of the relative view.
func topOf(from: UIView, margin: CGFloat = 0)

// Position the current view to the bottom of the relative view.
func bottomOf(from: UIView, margin: CGFloat = 0)

// ---------------------------------------------------------------------------

// Position the current view to the horizontal center of the relative view.
func centerHorizontalOf(from: UIView)

// Position the current view to the vertical center of the relative view.
func centerVerticalOf(from: UIView)

// Position the current view to the center of the relative view.
func centerOf(from: UIView)

// ---------------------------------------------------------------------------

// Position the current view to the left edge of the relative view.
func alignLeft(from: UIView, padding: CGFloat = 0)

// Position the current view to the right edge of the relative view.
func alignRight(from: UIView, padding: CGFloat = 0)

// Position the current view to the top edge of the relative view.
func alignTop(from: UIView, padding: CGFloat = 0)

// Position the current view to the bottom edge of the relative view.
func alignBottom(from: UIView, padding: CGFloat = 0)

// ---------------------------------------------------------------------------

// Position the current view to the left edge of the super view.
func alignSuperLeft(padding: CGFloat = 0)

// Position the current view to the right edge of the super view.
func alignSuperRight(padding: CGFloat = 0)

// Position the current view to the top edge of the super view.
func alignSuperTop(padding: CGFloat = 0)

// Position the current view to the bottom edge of the super view.
func alignSuperBottom(padding: CGFloat = 0)

// ---------------------------------------------------------------------------

// Position the current view to the horizontal center of the super view.
func centerHorizontalSuper()

// Position the current view to the vertical center of the super view.
func centerVerticalSuper()

// Position the current view to the center of the super view.
func centerInSuper()

// ---------------------------------------------------------------------------

// Apply the same size as the super view.
func sizeOfSuper(margin: CGFloat = 0)

// Apply the same size as the relative view.
func sizeOf(from: UIView, margin: CGFloat = 0)

// Apply custom size to the current view.
func size(width: CGFloat, height: CGFloat)

// Apply the same width size as the super view.
func widthOfSuper()

// Apply the same width size as the relative view.
func widthOf(from: UIView)

// Apply custom width size to the current view.
func width(_ width: CGFloat)

// Apply the same height size as the super view.
func heightOfSuper()

// Apply the same height size as the relative view.
func heightOf(from: UIView)

// Apply custom height size to the current view.
func height(_ height: CGFloat)

// ---------------------------------------------------------------------------

// Finalize the changed layout to the current view.
func apply()

Requirements

  • Swift 3.0+
  • Xcode 8.0+
  • iOS 8.0+

Installation

pod 'MGRelativeKit'
github "magi82/MGRelativeKit"

Author

magi82, [email protected]

License

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

mgrelativekit's People

Contributors

magi82 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.