这是一个基于 UITextView 的包装器,提供了在输入文本中查找和标记标签的支持。查看示例项目以获取想法。
要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install
。
@property (weak, nonatomic) IBOutlet TagsTextView *tagsInputView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// setup tags text view
// Setup Tags Text View
self.tagsInputView.tagsMarker = kTagsMarker;
self.tagsInputView.placeholderText = DESCRIPTION_TEXT_VIEW_PLACEHOLDER;
self.tagsInputView.textDefaultAttributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:15],
NSForegroundColorAttributeName:[UIColor blackColor],
NSBackgroundColorAttributeName: [UIColor whiteColor]};
self.tagsInputView.placeholderDefaultAttributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:15],
NSForegroundColorAttributeName:[UIColor lightGrayColor]};
self.tagsInputView.delegate = self;
}
#pragma mark - TagsTextViewDelegate
- (void)tagsTextViewUpdatedText:(NSString * __nullable)text {
// Here is all the string
}
- (void)tagsTextViewUpdatedTags:(NSArray * __nullable)tags {
NSMutableString *tagsString = [[NSMutableString alloc] init];
for (NSString *tag in tags) {
[tagsString appendString:[NSString stringWithFormat:@"%@ ", tag]];
}
self.relatedTagsLabel.text = tagsString;
}
iOS 8 或更高版本
CCTagsTextView 通过 CocoaPods 可用。要安装它,只需将以下行添加到您的 Podfile 中
pod "CCTagsTextView"
Daniel Mandea, [email protected]
CCTagsTextView 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。