Giter VIP home page Giter VIP logo

ustack's Introduction

UStack

A tool for StackView in UIKit.

Requirements

  • iOS 11.0+
  • Xcode 12.5+

Use cases

HStackView use-case:

let label = UILabel()
let button = UIButton()
let simpleView = UIView()

let hstack = HStackView {
    label
    button
    simpleView
}

VStackView use-case:

let label = UILabel()
let button = UIButton()
let simpleView = UIView()

let vstack = VStackView {
    label
    button
    simpleView
}

Nested use-case:

let refresh = Bool.random()
let refreshAnother = Bool.random()
let idx = Int.random(in: 1 ... 12)
HStackView {
  VStackView {
    UILabel()
    UIButton()
  }
  if refresh {
    VStackView {
      UIImageView()
      UIView()
    }
  }
  if refreshAnother {
    VStackView {
      UIImageView()
      UIView()
    }
  } else {
      UIView()
  }
  UIView().withSubViews {
    HStackView {
      UILabel()
      UIButton()
    }
  }
}

ps: every control flow will be treated as a block, give the simplest VStack for example:

  • buildExpression(_:) -> UILabel
  • buildExpression(_:) -> UIButton
  • buildBlock(_:) -> VStackView
  • buildExpression(_:) -> VStackView

Sample

UStack

As the example image above, the implement code:

private lazy var registerActionStack = VStackView(spacing: minorSpacing, alignment: .fill) {
  registerButton
  UIView.spacer()
  loginButton
}

private lazy var registerPolicyStack = HStackView(spacing: mediumSpacing) {
  UIView.spacer()
  policyCircleButton
  tipLabel
  policyInfoButton
  UIView.spacer()
}

private lazy var contentStack = VStackView(spacing: mainMargin, alignment: .center) {
  sloganImageView
  loginLogoImageView
  registerActionStack
  UIView.spacer()
  registerPolicyStack
}

and the layout code:

view.withSubViews {
  contentStack
}

contentStack.snp.makeConstraints {
  $0.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(topPadding)
  $0.leading.trailing.equalToSuperview().inset(horizontalPadding)
  $0.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
}

registerButton.snp.makeConstraints {
  $0.width.equalTo(view).inset(horizontalPadding)
}

Installation

Swift Package Manager

  • File > Swift Packages > Add Package Dependency
  • Add https://github.com/foxsin10/UStack.git
  • Select "Up to Next Major" with "2.0.0"

CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!

target 'MyApp' do
  pod 'UStack', '~> 2.3.0'
end

License

UStack is released under the MIT license. See LICENSE for details.

ustack's People

Contributors

foxsin10 avatar

Stargazers

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