LMFeedTextView
Overview
The LMFeedTextView
is a customizable text view that extends UITextView
with support for placeholder text, custom attributes, line counting, and disabled character sets. It is designed for rich text input in feed UIs.
File Location:
LMFeedTextView.swift
Functionality
UI Components
- Inherits all properties and methods from
UITextView
placeHolderText
: Placeholder text displayed when the text view is emptyplaceholderAttributes
: Attributes for the placeholder texttextAttributes
: Attributes for the main textnumberOfLines
: Computed property for the number of lines in the text view
Methods
setDisabledCharacters(_:)
: Sets a set of characters that are not allowed in the text viewtranslatesAutoresizingMaskIntoConstraints() -> Self
: Disables autoresizing mask translation and returns self for chainingaddDoneButtonOnKeyboard()
: Adds a toolbar with a Done button above the keyboardsetAttributedText(from:prefix:)
: Sets the text with attributes, optionally with a prefixgetText() -> String
: Returns the trimmed text, or an empty string if placeholder is shown
Delegate Methods
- Implements
UITextViewDelegate
for editing, placeholder, and change observation
Customization
CustomFeedTextView.swift
class CustomFeedTextView: LMFeedTextView {
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
// Custom setup
}
required init?(coder: NSCoder) {
super.init(coder: coder)
// Custom setup
}
// Add customizations as needed
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LMUIComponents.shared.textView = CustomFeedTextView.self
// ...
return true
}