Studie
Studie

Reputation: 799

How to insert a UITextView to a UIImageView

I'm programming an application, in wich you create UIImageView-objects.
The color of these objects can be set.

But the next step I am trying to do is: set a TextView in the imageView, but this text should entered by the user (certainly realized with the class UIKeyboard.)

Im sum: I have a imageView, which needs an editable UITextView in it.

Do you have any idea how it could be realized?

Upvotes: 0

Views: 843

Answers (2)

Daniel
Daniel

Reputation: 23359

Your approach is wrong.

You want an image view because the app lets you "create an image"

In reality and technically this isn't correct, what you will want to be doing is using a simple UIView to set he colour of an area, and you an place a UITextField or UITextView over that.

A UIImageView is a very specific UIView subclass for displaying images. You can't add your other UI inside of it, the best you could do is over it.

I you do use a UIView, when you're done you need to "convert" your UIView to an image which you can then use to save, send etc

For more about that check out Save UIView's representation to file

Upvotes: 3

Lukas
Lukas

Reputation: 1543

You simply want to subclass UIImageView and add a UITextView during init. Like this

@interface MyImageView : UIImageView {   

}
@property (nonatomic, strong) UITextView *textView;
@end

And the implementation

@implementation MyImageView
- (id)init {
    if ((self = [super init])) {
        self.textView = [[UITextView alloc] initWithFrame:CGRectMake(...)];
        [self addSubview:self.textView];
    }
    return self;
}
@end

Upvotes: 0

Related Questions