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 contenttextEdgeInsets
: Insets for the label's text
Methods & Properties
translatesAutoresizingMaskIntoConstraints() -> Self
: Disables autoresizing mask translation and returns self for chainingsetPadding(with:)
: Sets padding for all edges using aUIEdgeInsets
valuepaddingLeft
,paddingRight
,paddingTop
,paddingBottom
: Inspectable properties for setting individual edge insetstextRect(forBounds:limitedToNumberOfLines:)
: Calculates the drawing rectangle for the label's text, considering insetsdrawText(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
}