Skip to main content

LMFeedButton

Overview

The LMFeedButton is a customizable button widget that extends UIButton with additional functionality for styling, layout, and state management. It provides convenient methods for configuring appearance, managing content layout with icons and text.

File Location:
LMFeedButton.swift

Functionality

UI Components

  • titleLabel: The button's title label for text display
  • imageView: The button's image view for icon display
  • layer: The button's layer for shadow and corner radius customization

Methods

  • init(frame:): Initializes the button with a frame
  • createButton(with:image:textColor:textFont:contentSpacing:imageSpacing:): Factory method to create a pre-configured button instance
  • translatesAutoresizingMaskIntoConstraints() -> Self: Disables autoresizing mask translation and returns self for chaining
  • setContentInsets(with:): Sets content insets for iOS 15+ compatibility
  • setImageInsets(with:): Sets image edge insets for iOS 15+ compatibility
  • centerTextAndImage(spacing:): Centers text and image with specified spacing, supporting RTL layouts
  • setFont(_:): Sets the button's title label font

Customization

CustomFeedButton.swift
class CustomFeedButton: LMFeedButton {
override init(frame: CGRect) {
super.init(frame: frame)
setupDefaultAppearance()
}

private func setupDefaultAppearance() {
backgroundColor = .systemGreen
setTitleColor(.white, for: .normal)
layer.cornerRadius = 10
}

override func setFont(_ font: UIFont) {
super.setFont(font)
// Add custom font configuration
}
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LMUIComponents.shared.button = CustomFeedButton.self
// ...
return true
}