OEMentions
一个易于向uitextview添加提及的组件,类似于Facebook和Instagram。它还包括一个tableview来展示用户列表进行选择。该组件是用Swift编写的。
主要功能
- 可展开的UITextView(也可展开UITextView容器)
- 在输入“@”时显示和管理用户列表的位置("@"可以被换成任何字符)
- 可自定义提及文本
安装
Cocoapods
pod 'OEMentions'
手动
您可以将OEMentions.swift
文件手动导入到项目文件夹中
使用示例
您可以在 ViewController.swift 中看到一个完整的实现。
- 参考 UITextView 输出和“可选:容器(包含 UITextView 的 UIView)”
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var textView: UITextView!
- 创建一个 OEMention 变量
var oeMentions:OEMentions!
- 创建一个包含用户信息(id、姓名)的 OEObejct 数组
let oeObjects = [OEObject(id: 1,name: "Elsie Easterling"), OEObject(id: 2,name: "Caterina Misiewicz"), OEObject(id: 3,name: "Ruben Dematteo")]
- 初始化 OEMentions
oeMentions = OEMentions(containerView: containerView, textView: textView, mainView: self.view, oeObjects: oeObjects)
- 将 UITextView 代理分配给 OEMentions
textView.delegate = oeMentions
- (可选)OEMentionsDelegate:选择用户的代理方法
class ViewController: UIViewController, OEMentionsDelegate
oeMentions.delegate = self
func mentionSelected(id:Int, name: String) {
// Do something with selected id and name
}
定制
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
许可
MIT 许可证
版权所有 © 2019 Omar Alessa
任何人可以在不收取任何费用的情况下获得此软件及相关文档的副本(“软件”),按以下条件使用软件,包含但不限于使用的权利、复制、修改、合并、发布、分发、再许可和/或销售软件副本,以及允许获得软件的个人执行上述操作
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“现状”提供,不提供任何明示或默示的保证,包括但不限于适销性、对特定用途适用性和非侵权性。在任何情况下,包括但不限于合同、侵权或其他方式产生的索赔、损害或其他责任,其作者或版权所有者不应对任何索赔、损害或其他责任承担法律责任。