Skip to main content

LMView

Overview

The LMView is a customizable view widget that extends UIView and provides a standardized approach to view setup, layout, styling, and lifecycle management. It includes utility methods for corner radius, borders, shadows, constraints, and subview management, making it a flexible building block for LikeMinds UI modules.

File Location:
LMView.swift

Functionality

UI Components

  • layer: The view's layer for styling customization

Properties

  • heightViewSize: The default height for the view based on screen width
  • widthViewSize: The default width for the view based on screen width
  • heightOfScreen: The height of the device screen
  • widthOfScreen: The width of the device screen
  • minSizeOfScreen: The minimum of the screen's width and height

Methods

Initialization & Lifecycle

  • init(frame:): Initializes the view and sets up subviews, layouts, actions, and observers
  • init?(coder:): Unavailable initializer
  • layoutSubviews(): Lays out subviews and applies styles
  • deinit: Cleans up observers

Layout & Styling

  • translatesAutoresizingMaskIntoConstraints() -> Self: Disables autoresizing mask translation and returns self for chaining
  • addShadow(): Adds a default shadow effect to the view
  • roundCorners(_:with:): Rounds specific corners with a given radius
  • cornerRadius(with:): Sets the corner radius for the view
  • borderColor(withBorderWidth:with:): Sets the border color and width
  • roundCornerWithShadow(...): Rounds corners and adds a shadow with custom parameters

Constraint & Subview Management

  • pinSubView(subView:padding:): Pins a subview to the edges with optional padding
  • addSubviewWithDefaultConstraints(_:): Adds a subview and pins it with default constraints
  • safeAreaPinSubView(subView:padding:): Pins a subview to the safe area with optional padding
  • addConstraint(...): Adds layout constraints for top, bottom, leading, trailing, centerX, and centerY anchors
  • setHeightConstraint(with:relatedBy:priority:): Sets a height constraint with a constant value
  • setWidthConstraint(with:relatedBy:priority:): Sets a width constraint with a constant value
  • setHeightConstraint(with:relatedBy:priority:multiplier:constant:): Sets a height constraint relative to another anchor
  • setWidthConstraint(with:relatedBy:priority:multiplier:constant:): Sets a width constraint relative to another anchor

LMViewLifeCycle Protocol Methods

  • setupViews(): Sets up the view hierarchy
  • setupLayouts(): Sets up layout constraints
  • setupActions(): Sets up action handlers
  • setupObservers(): Sets up observers for data binding
  • setupAppearance(): Sets up visual appearance