views:

3208

answers:

3

Hi, how can I add a background image to UITextView?

Thanks.

A: 

Not sure about, but you can try the following, assuming that your background image is handled by a UIImageView:

[myTextView addSubview: myImageView];

Note that you may need to change the value of the alpha/opaque properties of your UITextView.

Kind Regards.

unforgiven
+6  A: 

You can have a UIImageView containing the background image and the UITextView as siblings, then in Interface Builder move the text view to overlap the image view (or add them both to the same parent view if doing it programmatically). You also have to make sure the text view is not opaque and give it a 0% opacity background.

duncanwilcox
In my mind this is the right answer, in oxigen's method, if the background image has a "bottom border" then the user will see it scroll along with the text view as they enter text.
bpapa
+9  A: 
UITextView *textView = [[UITextView alloc]initWithFrame: window.frame];
    textView.text = @"text\n text\n text";
    UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame];
    imgView.image = [UIImage imageNamed: @"myImage.jpg"];
    [textView addSubview: imgView];
    [textView sendSubviewToBack: imgView];
    [window addSubview: textView];
oxigen
I think duncanwilcox's answer is preferable as the method described in this answer will cause the "background image" to scroll along with the content as the user types.
bpapa
Remember to release alloced objects.after: [textView addSubview: imgView];add: [imgView release];add to the end: [textView release];
MattDiPasquale