hmzfier
hmzfier

Reputation: 554

Xcode: Position Images Inside UITextView

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!

Upvotes: 0

Views: 636

Answers (2)

Mayank Patel
Mayank Patel

Reputation: 3908

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;

Upvotes: 0

Abhishek
Abhishek

Reputation: 1702

Check out this library it might help you

https://github.com/dzog/ImgGlyph

Upvotes: 0

Related Questions