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 - foxsin10/UStack: Use less code to layout views in UIKit or Cocoa

BranchesTags
Open more actions menu

Latest commit

 

History

55 Commits
55 Commits

Folders and files

NameName
Last commit message
Last commit date
.swiftpm/xcode
.swiftpm/xcode
 
 
Sources/UStack
Sources/UStack
 
 
Tests/UStackTests
Tests/UStackTests
 
 
images
images
 
 
.gitignore
.gitignore
 
 
.swift-version
.swift-version
 
 
LICENSE
LICENSE
 
 
Package.swift
Package.swift
 
 
README.md
README.md
 
 
UStack.podspec
UStack.podspec
 
 

Repository files navigation

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.

About

Use less code to layout views in UIKit or Cocoa

Topics

hstacklayoutswiftvstack

Resources

Readme
MIT license
Activity

Stars

3 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — 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.