An easy way to add mentions in UITextView.
- Swift 3.0
- Xcode 8
- iOS 8.0+
To run the example project, clone the repo, and run pod install
from the Example directory first.
CocoaPods (recommended)
use_frameworks!
pod 'Mentions'
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."
// 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()
}
magicmon, http://magicmon.github.io
Mentions is available under the MIT license. See the LICENSE file for more info.