This helps make the view's configuration code, hierarchy code, and constraint code neat.

Related tags

Layout UIBaseKit
Overview

UIBaseKit

Swift Version License Platform

🤔 So far, when coding for a view, we wrote a combination of configuration code, constraint code, and hierarchical code, resulting in a poor understanding of the source. So, I created a library that helps you separate this configuration code, constraint code, and hierarchical code to make it cleaner.

Usage

QuickStart

After inheriting from BaseViewController, override and implement the setupViews and setupConstraints methods.

import UIKit
import UIBaseKit

class SignUpViewController: BaseViewController {
  // MARK: - UI
  var usernameLabel: UILabel = {
    $0.textColor = .black
    $0.textAlignment = .right
    $0.font = .boldSystemFont(ofSize: 16.0)
    $0.text = "Username"
    return $0
  }(UILabel())

  ...

  var emailLabel: UILabel = {
    $0.textColor = .black
    $0.textAlignment = .right
    $0.font = .boldSystemFont(ofSize: 16.0)
    $0.text = "Email"
    return $0
  }(UILabel())

  ...

  /// After configure propertys for each view,
  /// return an array of views to add to the superview in desired order.
  override func setupViews() -> [CanBeSubview]? {
    // 1) configure views
    view.backgroundColor = .white
    registerKeyboardObservers()
    signUpButton.addTarget(self, action: #selector(signUpButtonDidTouch), for: .touchUpInside)

    ...

    // 2) return subviews
    /** 😍 viewController`s view hierarchy
      → keyboardAvoidView
         → containerView
             → usernameLabel
             → usernameTextField
             → emailLabel
             → emailTextField
             → passwordLabel
             → passwordTextField
      → signUpButton
    */
    let hierarchy = [
      keyboardAvoidView.addSubviews(
        containerView.addSubviews(
          usernameLabel,
          usernameTextField,
          emailLabel,
          emailTextField,
          passwordLabel,
          passwordTextField
        )
      ),
      signUpButton
    ]
    return hierarchy
  }

  /// Configure the constraints for each view.
  override func setupConstraints() {
    // 3) set constraints for each view added to superview.
    // 🤓Note: I set constraints for each view using my favorite `FluidAnchor` library.
    // https://github.com/audrl1010/FluidAnchor

    keyboardAvoidView.flu
      .leftAnchor(equalTo: view.leftAnchor)
      .topAnchor(equalTo: view.topAnchor)
      .rightAnchor(equalTo: view.rightAnchor)
      .bottomAnchor(equalTo: view.bottomAnchor)

    containerView.flu
      .topAnchor(equalTo: view.topAnchor, constant: 60)
      .leftAnchor(equalTo: view.leftAnchor, constant: 15)
      .rightAnchor(equalTo: view.rightAnchor, constant: -15)
      .heightAnchor(equalToConstant: 180)
    
      ...
  }
}

Support Classes

class BaseView: UIView { ... }
class BaseTableViewCell: UITableViewCell { ... }
class BaseCollectionViewCell: UICollectionViewCell { ... }
class BaseViewController: UIViewController { ... }

Installation

pod 'UIBaseKit'

Author

Myung gi son, [email protected]

License

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

You might also like...
✂ Easy to use and flexible library for manually laying out views and layers for iOS and tvOS. Supports AsyncDisplayKit.

ManualLayout Table of Contents Installation Usage API Cheat Sheet Installation Carthage Add the following line to your Cartfile. github "isair/ManualL

Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Not Apple Autolayout wrapper. Provides placeholders. Linux support.
Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Not Apple Autolayout wrapper. Provides placeholders. Linux support.

CGLayout Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Has cross-hierarchy coordinate space. Implemen

Expose layout margins and readable content width to SwiftUI's Views

SwiftUI Layout Guides This micro-library exposes UIKit's layout margins and readable content guides to SwiftUI. Usage Make a view fit the readable con

An experiment creating a particle emitter using the new TimelineView and Canvas views in SwiftUI
An experiment creating a particle emitter using the new TimelineView and Canvas views in SwiftUI

Particle Emitter An experiment creating a particle emitter using the new Timelin

Make your notification banners smaller and add some color to them

Liddell Liddell notification banners Installation Add this repository to your Package Manager: https://repo.litten.love Install Liddell Compiling Depe

LoadingButtton - Add button extendded from LoadingButton in the view and make it center horizontally
LoadingButtton - Add button extendded from LoadingButton in the view and make it center horizontally

LoadingButtton Usage/Examples Add button extendded from LoadingButton in the vie

Enables you to hide ur UIViews and make them screen/screen shot proof. objective c/c++ only

SecureView Enables you to hide ur UIViews and make them screen/screen shot proof. objective c/c++ only Usage UIWindow* mainWindow; - (void) setup {

Simple static table views for iOS in Swift.
Simple static table views for iOS in Swift.

Simple static table views for iOS in Swift. Static's goal is to separate model data from presentation. Rows and Sections are your “view models” for yo

Apple provides us two ways to use UIKit views in SwiftUI

RepresentableKit Apple provides us two ways to use UIKit views in SwiftUI: UIVie

Releases(0.1.1)
Owner
Myung gi son
iOS developer
Myung gi son
SwiftLayout - View hierarchy and autolayout DSL library

SwiftLayout view hierarchy and autolayout DSL library goal 뷰의 계층구조와 constraint 관

iOS Swifty Krew 104 Dec 28, 2022
A Swift utility to make updating table views/collection views trivially easy and reliable.

ArrayDiff An efficient Swift utility to compute the difference between two arrays. Get the removedIndexes and insertedIndexes and pass them directly a

Adlai Holler 100 Jun 5, 2022
UITableView based component designed to display a hierarchy of expandable/foldable comments.

SwiftyComments UITableView based component designed to display a hierarchy of expandable/foldable comments. Installation Manually Just copy the .swift

Stéphane Sercu 220 Dec 22, 2022
Compose is a library that helps you compose complex and dynamic views.

Compose is a data driven library that will help compose your complex and dynamic Views. It helps you create complex and dynamic Views using easy and s

OLX Brasil 123 Jun 9, 2021
Swift-picker-views - inline single and multi picker views for UIKit. Without tableview! Easy and simple

swift-picker-views Inline single and multiple picker views for UIKit. No tablevi

IBRAHIM YILMAZ 2 Jan 31, 2022
🇰🇷 An app that helps non Korean speakers to learn Hangul easily and effectively.

?? HangulKing HangulKing is the fastest way to the throne of Hangul, the Korean alphabets! HangulKing helps the users learn Hangul easily, providing m

개발자아카데미_포스텍 7 Nov 26, 2022
Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]

Extremely Fast views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainabl

layoutBox 2.1k Dec 22, 2022
Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast

Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]

layoutBox 2.1k Jan 2, 2023
iOS App that helps you breath properly.

Breathing App iOS App that helps you breath properly. I created this iOS app in my Intro to iOS Develepmont class at Hunter College. I am not a profes

Kevin Salamanca 0 Dec 24, 2021
The fast path to autolayout views in code

NorthLayout The fast path to autolayout views in code Talks https://speakerdeck.com/banjun/auto-layout-with-an-extended-visual-format-language at AltC

banjun 36 Jul 15, 2022