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 widthwidthViewSize
: The default width for the view based on screen widthheightOfScreen
: The height of the device screenwidthOfScreen
: The width of the device screenminSizeOfScreen
: The minimum of the screen's width and height
Methods
Initialization & Lifecycle
init(frame:)
: Initializes the view and sets up subviews, layouts, actions, and observersinit?(coder:)
: Unavailable initializerlayoutSubviews()
: Lays out subviews and applies stylesdeinit
: Cleans up observers
Layout & Styling
translatesAutoresizingMaskIntoConstraints() -> Self
: Disables autoresizing mask translation and returns self for chainingaddShadow()
: Adds a default shadow effect to the viewroundCorners(_:with:)
: Rounds specific corners with a given radiuscornerRadius(with:)
: Sets the corner radius for the viewborderColor(withBorderWidth:with:)
: Sets the border color and widthroundCornerWithShadow(...)
: Rounds corners and adds a shadow with custom parameters
Constraint & Subview Management
pinSubView(subView:padding:)
: Pins a subview to the edges with optional paddingaddSubviewWithDefaultConstraints(_:)
: Adds a subview and pins it with default constraintssafeAreaPinSubView(subView:padding:)
: Pins a subview to the safe area with optional paddingaddConstraint(...)
: Adds layout constraints for top, bottom, leading, trailing, centerX, and centerY anchorssetHeightConstraint(with:relatedBy:priority:)
: Sets a height constraint with a constant valuesetWidthConstraint(with:relatedBy:priority:)
: Sets a width constraint with a constant valuesetHeightConstraint(with:relatedBy:priority:multiplier:constant:)
: Sets a height constraint relative to another anchorsetWidthConstraint(with:relatedBy:priority:multiplier:constant:)
: Sets a width constraint relative to another anchor
LMViewLifeCycle Protocol Methods
setupViews()
: Sets up the view hierarchysetupLayouts()
: Sets up layout constraintssetupActions()
: Sets up action handlerssetupObservers()
: Sets up observers for data bindingsetupAppearance()
: Sets up visual appearance