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 displayimageView
: The button's image view for icon displaylayer
: The button's layer for shadow and corner radius customization
Methods
init(frame:)
: Initializes the button with a framecreateButton(with:image:textColor:textFont:contentSpacing:imageSpacing:)
: Factory method to create a pre-configured button instancetranslatesAutoresizingMaskIntoConstraints() -> Self
: Disables autoresizing mask translation and returns self for chainingsetContentInsets(with:)
: Sets content insets for iOS 15+ compatibilitysetImageInsets(with:)
: Sets image edge insets for iOS 15+ compatibilitycenterTextAndImage(spacing:)
: Centers text and image with specified spacing, supporting RTL layoutssetFont(_:)
: 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
}