Mentions
An easy way to add mentions in UITextView.
Demo
Requirements
- Swift 5.0
- Xcode 11
- iOS 10.0+
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Installation
CocoaPods (recommended)
use_frameworks!
pod 'Mentions'
Usage
var mentionTextView = MentionTextView()
view.addSubview(mentionTextView)
// initial text with mention.
mentionTextView.mentionText = "who is your favorite actor or actress? I like [Will Smith] and [Robert Pattinson] the best."
mentionTextView.deleteType = .cancel // or .delete
// add to mention.
mentionTextView.insert(to: "Leonardo DiCaprio", with: mentionTextView.selectedRange)
If you want to show the text that contains the mention, set it as follows.
var textLabel = MentionLabel()
view.addSubview(textLabel)
textLabel.text = mentionTextView.mentionText
// or Add the text of the mention inside special characters "[]".
textLabel.text = "[Brad Pitt]"
// show the mention text.
textLabel.tapHandler = { (mention) in
let alert = UIAlertView(title: "", message: mention, delegate: nil, cancelButtonTitle: nil, otherButtonTitles: "OK")
alert.show()
}
Author
magicmon, http://magicmon.github.io
License
Mentions is available under the MIT license. See the LICENSE file for more info.