0

I have a string that is added to the UITextView, and I would like to add images after a certain world in that string.

Example:

@property (strong, nonatomic) IBOutlet UITextView *textview;    

textview.text = @"This is an icon of a cat. And this is an 
icon of a car. Here is more random text.";                      

This is an example of what I want:

enter image description here

How do I append and position images after a certain word?

I have an array that detects certain words:

NSArray *detectWords = @[@"cat", @"car"];

So I can detect when certain words show up in the text of a textview, but I'm not sure how to add an image right after those words.

Also, the string of words will vary in different situations (not static), so pre-positioning everything on the interface builder is not an option for me.

Thanks in advance!

hmzfier
  • 554
  • 9
  • 21
  • You can either make a font with the images, and specify the correct glyph with an attributed string, or you can add `UIImageView`s, calculate the rects for the images and use Core Text to wrap the text around them. – Aaron Brager Dec 26 '14 at 04:24
  • http://stackoverflow.com/questions/20930462/ios-7-textkit-how-to-insert-images-inline-with-text look at this – Sport Dec 26 '14 at 06:07

2 Answers2

0

Check out this library it might help you

https://github.com/dzog/ImgGlyph

Abhishek
  • 1,682
  • 2
  • 17
  • 29
0

Like this way, you can also do this,I hope it will help u Here is how to put an image in the right portion of a UITextField:

 UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 500, 20)];
 textField.rightViewMode = UITextFieldViewModeWhileEditing;

 UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
 imageView.image = [UIImage imageNamed:@"Dog.png"];
 textField.rightView = imageView;
Mayank Patel
  • 3,868
  • 10
  • 36
  • 59