Satyam
Satyam

Reputation: 15894

iphone - problem with background image of uitextview

I'm trying to add a back ground image to UITextView. The image is just a small border which will be placed at the top of text view. (the image resembles teared paper image). I'm using following code

  UIImageView *imgView = [[UIImageView alloc]initWithFrame: CGRectMake(0, 0, 320, 13)];
  imgView.image = [UIImage imageNamed: @"teared_paper.png"];
  [tView addSubview: imgView];
  [tView sendSubviewToBack: imgView];   
  [imgView release];

My text view's height is 150 pixels only. (text view occupies only small portion of view and it is at the top of the view so that it will appear to the user when keyboard is there)

The problem is that, when I add more lines of text, text view is scrolling automatically. And at the same time, the background image that I added is also scrolling. How can I prevent the background image to stay on the top all the time irrespective of scrolling.

Upvotes: 3

Views: 4627

Answers (3)

Ajay Sharma
Ajay Sharma

Reputation: 4517

Try it with:

UIImageView *imgView = [[UIImageView alloc]initWithFrame: CGRectMake(0, 0, 320, 13)];
imgView.image = [UIImage imageNamed: @"teared_paper.png"];
[tView addSubview: imgView];
[imgView release];

Just make textView transparent :

[textView setBackgroundColor:[UIColor clearColor]];

no need to bring the subview to front.

Hope this works for u..

Upvotes: 1

Denis Hennessy
Denis Hennessy

Reputation: 7463

Don't add the image view as a subview of the text view. Instead, have both the image view and the text view as children of the main view, position the image view behind the text view, and set the background color of the text view to transparent with:

[tView setBackgroundColor:[UIColor clearColor]];

Upvotes: 2

Cameron Hotchkies
Cameron Hotchkies

Reputation: 1509

Can you try putting a UIImageView behind the UITextView and making the UITextView transparent?

Upvotes: 1

Related Questions