Iphone - problem with uitextview background image

I am trying to add a reverse image to a UITextView. The image is a small border that will be placed at the top of the text view. (the image resembles a torn paper image). I am using the 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 is only 150 pixels tall. (the text view takes up only a small part of the review, and it is at the top of the view so that it is displayed to the user when the keyboard is there)

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

+3
source share
3 answers

Do not add an image view as a text view subview. Instead, both the image view and the text view as children of the main view, place the image behind the text view and set the background color in the text view to transparent using:

[tView setBackgroundColor:[UIColor clearColor]];
+2
source

Can you try to put a UIImageView behind a UITextView and make the UITextView transparent?

+1
source

Try:

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 subroutine forward.

Hope this works for u ..

+1
source

Source: https://habr.com/ru/post/1776498/


All Articles