LMLabel
Overview
The LMLabel
is a customizable label widget that extends UILabel
with additional functionality for text padding and layout management. It provides convenient methods for configuring text insets and managing content layout with customizable padding options.
File Location:
LMLabel.swift
Functionality
UI Components
textEdgeInsets
: The edge insets applied to the text contenttext
: The label's text contentlayer
: The label's layer for styling customization
Methods
init(frame:)
: Initializes the label with a frametranslatesAutoresizingMaskIntoConstraints() -> Self
: Disables autoresizing mask translation and returns self for chainingtextRect(forBounds:limitedToNumberOfLines:)
: Overridden method to handle text insets in text rect calculationdrawText(in:)
: Overridden method to apply text insets during drawingsetPadding(with:)
: Sets padding for all edges using UIEdgeInsetspaddingLeft
: IBInspectable property for left paddingpaddingRight
: IBInspectable property for right paddingpaddingTop
: IBInspectable property for top paddingpaddingBottom
: IBInspectable property for bottom padding
Customization
CustomLMLabel.swift
class CustomLMLabel: LMLabel {
override init(frame: CGRect) {
super.init(frame: frame)
setupDefaultAppearance()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupDefaultAppearance()
}
private func setupDefaultAppearance() {
textColor = .label
font = .systemFont(ofSize: 16)
numberOfLines = 0
lineBreakMode = .byWordWrapping
}
override func setPadding(with padding: UIEdgeInsets) {
super.setPadding(with: padding)
// Add custom padding behavior
}
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LMUIComponents.shared.customLabel = CustomLMLabel.self
// ...
return true
}