Skip to main content

LMFeedLabel

Overview

The LMFeedLabel is a customizable label widget that extends UILabel with additional functionality for padding and layout. It allows you to set custom edge insets for the label's text, making it easy to control spacing and appearance.

File Location:
LMFeedLabel.swift

Functionality

UI Components

  • text: The label's text content
  • textEdgeInsets: Insets for the label's text

Methods & Properties

  • translatesAutoresizingMaskIntoConstraints() -> Self: Disables autoresizing mask translation and returns self for chaining
  • setPadding(with:): Sets padding for all edges using a UIEdgeInsets value
  • paddingLeft, paddingRight, paddingTop, paddingBottom: Inspectable properties for setting individual edge insets
  • textRect(forBounds:limitedToNumberOfLines:): Calculates the drawing rectangle for the label's text, considering insets
  • drawText(in:): Draws the label's text within the specified rectangle, applying insets

Customization

CustomFeedLabel.swift
class CustomFeedLabel: LMFeedLabel {
override init(frame: CGRect) {
super.init(frame: frame)
setupDefaultAppearance()
}

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

private func setupDefaultAppearance() {
setPadding(with: UIEdgeInsets(top: 8, left: 12, bottom: 8, right: 12))
backgroundColor = .systemGray6
layer.cornerRadius = 8
}
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LMUIComponents.shared.label = CustomFeedLabel.self
// ...
return true
}