Skip to main content

LMStackView

Overview

The LMStackView is a customizable stack view widget that extends UIStackView with additional functionality for layout management and subview handling. It provides convenient methods for managing arranged subviews and Auto Layout constraints.

File Location:
LMStackView.swift

Functionality

UI Components

  • arrangedSubviews: The array of views arranged by the stack view
  • axis: The axis along which the arranged views are laid out
  • distribution: The distribution of the arranged views along the stack view's axis
  • alignment: The alignment of the arranged views perpendicular to the stack view's axis
  • spacing: The distance between adjacent arranged views

Methods

  • init(frame:): Initializes the stack view with a frame
  • translatesAutoresizingMaskIntoConstraints() -> Self: Disables autoresizing mask translation and returns self for chaining
  • removeAllArrangedSubviews(): Removes all arranged subviews and deactivates their constraints

Customization

CustomLMStackView.swift
class CustomLMStackView: LMStackView {
override init(frame: CGRect) {
super.init(frame: frame)
setupDefaultAppearance()
}

required init(coder: NSCoder) {
super.init(coder: coder)
setupDefaultAppearance()
}

private func setupDefaultAppearance() {
axis = .vertical
distribution = .fill
alignment = .fill
spacing = 8
backgroundColor = .clear
}

override func removeAllArrangedSubviews() {
super.removeAllArrangedSubviews()
// Add custom cleanup behavior
}
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LMUIComponents.shared.customStackView = CustomLMStackView.self
// ...
return true
}