An easy way to add mentions to uitextview like Facebook and Instagram

Overview

OEMentions

Platforms Language CocoaPod License

An easy way to add mentions to uitextview like Facebook and Instagram. It also include a tableview to show the users list to choose from. The component is written in Swift.

demo2_gif demo3_gif

Main features

  • Expandale UITextView (also expandle UITextView container)
  • Show and manage position of users list when "@" is typed ("@" can be changed to any character)
  • Customizable mention text

Installation

Cocoapods

pod 'OEMentions'

Manual

You can import OEMentions.swift file manually to your project folder

Usage Example

You can see a full implementation in ViewController.swift

  1. Refrence UITextView outlet and "Optional: Container (UIView that has UITextView in it)"
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var textView: UITextView!
  1. Create a OEMention variable
var oeMentions:OEMentions!
  1. Create an OEObejct array that contain users info (id, name)
let oeObjects = [OEObject(id: 1,name: "Elsie Easterling"), OEObject(id: 2,name: "Caterina Misiewicz"), OEObject(id: 3,name: "Ruben Dematteo")]
  1. Initialize the OEMentions
oeMentions = OEMentions(containerView: containerView, textView: textView, mainView: self.view, oeObjects: oeObjects)
  1. Assign UITextView delegate to OEMentions
textView.delegate = oeMentions
  1. (Optional) OEMentionsDelegate: delegate method for the chosen user
class ViewController: UIViewController, OEMentionsDelegate
oeMentions.delegate = self
func mentionSelected(id:Int, name: String) {
      
      // Do something with selected id and name
      
}

Customization

changeMentionCharacter(character: String)
changeMentionTableviewBackground(color: UIColor)
// Color of the mention tableview name text
OEMentions.nameColor
// Font of the mention tableview name text
OEMentions.nameFont
// Rest of the UITextView text color
OEMentions.notMentionColor

License

MIT License

Copyright (c) 2019 Omar Alessa

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Mention list not updating as text changes

    Mention list not updating as text changes

    Describe the bug When the user starts the mention using "@" the list of entities appears but if you type "@ab" then instead of filtering the mention list with only those id, name starting with ab the list doesn't change

    To Reproduce Steps to reproduce the behavior:

    1. Download the sample app
    2. Write "@" and the list of names will appear
    3. Write "@cat" and the list will not update

    Expected behavior The list should filter as user types

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    opened by mrafayfarooq 7
  • Problems with Dark mode

    Problems with Dark mode

    Hello! The problem we are having with the library is that when you select one of the users, all the text that was already written in the textView is changed to black. So for the dark mode, it becomes impossible to read.

    No matter what color you indicate in this line of code, it is always modified to black once a tableView option is selected. image

    This is what happens: WhatsApp Image 2019-11-19 at 6 20 46 PM

    As you can see the text before the mention is in black WhatsApp Image 2019-11-19 at 6 20 46 PM (1)

    What we are trying to achieve is that the text that is not a mention is displayed in system label format after selecting a user to be seen in both modes of iOS 13.

    opened by kelvinperea 1
  • this framework just working on 13.0 or above i think should be least version 11.0

    this framework just working on 13.0 or above i think should be least version 11.0

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    opened by tiskender2 0
  • Beginning of new line fix

    Beginning of new line fix

    Problem: When the user goes to the next line and try to mention it doesn't work

    Fix: Add the condition of "\n" to recognize it as a valid case to show the mentions list

    opened by omar14 0
  • multiple mention and removing names crashes the app due to text range issue

    multiple mention and removing names crashes the app due to text range issue

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    opened by PrincessMine 0
  • position of user list, and oeMentions list of properties

    position of user list, and oeMentions list of properties

    Is your feature request related to a problem? Please describe. First I am not sure how the mention list positioned but what I figured out is it will be placed in the containerView now, with your design that will work properly. but with other it will not. for example with my design I have textview within UIView1 and under it a UIView2. so when I choose the UIView1 as the containerView the list will be above my textview which in my case out of device height but when the container view is UIview2, the list will appear but my UIview2 will out of place after the keyboard dismissed

    also the font won't change --> because the customizable properties are not accessible. it says 'nameFont' is inaccessible due to 'internal' protection level

    Describe the solution you'd like so for me mention should will be recognized only by typing and with optional list if wanted.

    Additional context

    opened by mohamedFalah 0
  • mentionsIndexes become incorrect if we add additional text before the last mention

    mentionsIndexes become incorrect if we add additional text before the last mention

    Describe the bug The start location of the mention will be incorrect if we go back and add additional text before the Mention.

    To Reproduce Steps to reproduce the behavior:

    1. Add the first mention. mentionsIndexes has start location 0
    2. Move the cursor to before the text, input "ABC"

    Expected behavior mentionsIndexes should have startLocation 3

    Actual behavior mentionsIndexes still have start location 0

    opened by hainhathoang88 0
  • How can I set OEMentions with items from a network request?

    How can I set OEMentions with items from a network request?

    I want to make a network request to get some json response which I will use to create oeObjects. Where can I make this network request as soon as the user types in the @ and tries to find someone?

    opened by tobitech 0
Owner
Omar Alessa
Omar Alessa
SZMentionsSwift is a lightweight mentions library for iOS.

SZMentionsSwift is a lightweight mentions library for iOS. This library was built to assist with the adding, removing and editing of a mention within a textview.

Steven Zweier 122 Dec 12, 2022
Easiest way to create an attributed UITextView (with support for multiple links and from html)

AttributedTextView Easiest way to create an attributed UITextView (with support for multiple links and html). See the demo app and the playground for

Edwin Vermeer 430 Nov 24, 2022
AttributedText is a Swift µpackage that provides NSAttributedString rendering in SwiftUI by wrapping either an NSTextView or a UITextView depending on the platform.

AttributedText AttributedText is a Swift µpackage that provides NSAttributedString rendering in SwiftUI by wrapping either an NSTextView or a UITextVi

null 1 Jul 18, 2022
Like a SwiftUI ViewBuilder, but for Text

TextBuilder Introduction Text composition in SwiftUI can often be cumbersome, especially when there's logic affecting its format and content. TextBuil

David Roman 180 Dec 26, 2022
PySwiftyRegex - Easily deal with Regex in Swift in a Pythonic way

PySwiftyRegex Easily deal with Regex in Swift in a Pythonic way.

Ce Zheng 232 Oct 12, 2022
An easier way to compose attributed strings

TextAttributes makes it easy to compose attributed strings. let attrs = TextAttributes() .font(name: "HelveticaNeue", size: 16) .foregroundCol

Damien 2.2k Dec 31, 2022
Write amazing, strong-typed and easy-to-read NSPredicate.

PredicateFlow Write amazing, strong-typed and easy-to-read NSPredicate. This library allows you to write flowable NSPredicate, without guessing attrib

Andrea Del Fante 103 Aug 12, 2022
A TextView that provides easy to use tagging feature for Mention or Hashtag

Tagging A TextView that provides easy to use tagging feature for Mention or Hashtag. Introduction Tagging is a UIView that encloses a TextView that co

DongHee Kang 110 Jan 3, 2023
Acčento is an easy-to-use tool for adding Czech diacritics to copied text.

Acčento is an easy-to-use tool for adding Czech diacritics to copied text. The app lives in the menu bar and is activated using a global hot key.

Matty Cross 3 Sep 16, 2021
Easy string decoration with styles

StyleDecorator Design string simply by linking attributes. Example Create Decorator with specific Style and link it at the end of needed string or wra

Dmytro Pylypenko 15 Nov 4, 2021
Easy Attributed String Creator

The main idea of this project is to have an online tool to be able to visually add formatting to a text and get back a swift and/or objective-c code t

Andres Canal 283 Dec 27, 2022
Markdown parsing and rendering for iOS and OS X

CocoaMarkdown Markdown parsing and rendering for iOS and macOS CocoaMarkdown is a cross-platform framework for parsing and rendering Markdown, built o

Indragie Karunaratne 1.2k Dec 12, 2022
A simple and customizable Markdown Parser for Swift

MarkdownKit MarkdownKit is a customizable and extensible Markdown parser for iOS and macOS. It supports many of the standard Markdown elements through

Bruno Oliveira 687 Dec 18, 2022
MarkdownView is a WKWebView based UI element, and internally use bootstrap, highlight.js, markdown-it.

MarkdownView is a WKWebView based UI element, and internally use bootstrap, highlight.js, markdown-it.

Keita Oouchi 1.8k Dec 21, 2022
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.

PrediKit A Swift NSPredicate DSL for iOS & OS X inspired by SnapKit, lovingly written in Swift, and created by that weird dude at KrakenDev. If you're

Hector Matos 542 Sep 24, 2022
A library for formatting strings on iOS and macOS

Sprinter Introduction What? Why? How? Usage Installation Integration Localization Thread Safety Advanced Usage Introduction What? Sprinter is a librar

Nick Lockwood 168 Feb 6, 2022
VEditorKit - Lightweight and Powerful Editor Kit built on Texture(AsyncDisplayKit)

VEditorKit provides the most core functionality needed for the editor. Unfortunately, When combined words are entered then UITextView selectedRange will changed and typingAttribute will cleared. So, In combined words case, Users can't continue typing the style they want.

David Ha 471 Dec 27, 2022
Markdown in SwiftUI, and some other interesting components.

RoomTime RoomTime is a bundle of tools developed in my app RoomTime Lite. ( ?? RoomTime Lite is still in development) Features TextArea AutoWrap Markd

Chen SiWei 56 Dec 20, 2022