Mentions 1.1.2

Mentions 1.1.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jul 2023
SPMSupports SPM

Maintained by TWSlidingView.



Mentions 1.1.2

  • By
  • magicmon

Mentions

Swift 5.7 Version Platform License

An easy way to add mentions in UITextView.

Demo

Demo

Requirements

  • Swift 5.7
  • Xcode 14.1
  • iOS 13.0+

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Swift Package Manager

The Swift Package Manager automates the distribution of Swift code. To use Mentions with SPM, add a dependency to https://github.com/magicmon/Mentions.git

CocoaPods

use_frameworks!

pod 'Mentions'

Usage

var mentionTextView = MentionTextView()
view.addSubview(mentionTextView)

// initial text with mention.
mentionTextView.setMentionText("www.google.com or [magicmon]", 
                               pattern: .mention,
                               prefixMention: "@")
mentionTextView.deleteType = .cancel // or .delete

// add to mention.
mentionTextView.insert(to: "anonymous", 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.setMentionText(mentionTextView.mentionText,
                         pattern: .mention,
                         prefixMention: "@")

// or Add the text of the mention inside special characters "[]".
textLabel.setMentionText("[Brad Pitt]")

// show the mention text.
textLabel.tapHandler = { (mention) in
  let alert = UIAlertController(title: "", message: mention, preferredStyle: .alert)
  alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
  self.present(alert, animated: true, completion: nil)
}

Author

magicmon, https://magicmon.tistory.com

License

Mentions is available under the MIT license. See the LICENSE file for more info.