Skip to main content

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 empty
  • placeholderAttributes: Attributes for the placeholder text
  • textAttributes: Attributes for the main text
  • numberOfLines: 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 view
  • translatesAutoresizingMaskIntoConstraints() -> Self: Disables autoresizing mask translation and returns self for chaining
  • addDoneButtonOnKeyboard(): Adds a toolbar with a Done button above the keyboard
  • setAttributedText(from:prefix:): Sets the text with attributes, optionally with a prefix
  • getText() -> 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
}