1

I'm facing a problem which takes me too long to solve. I built a view, which contains a ScrollView. in the ScrollView, there's a view, which contains an image, and a UITextView. the textview should be in a dynamic height, with scrolling disabled. the textview gets all the text, but cut it off, and shows only the text that fits the height. in addition, the ScrollView doesn't changes.

- (void)viewDidLoad

 ....
 //sets the text to the textview
 [self.contentArticle setText:[NSString stringWithString:xmlParser.articleContent]];
 //configures the scrollView
 [self configureScrollView];

 ....

- (void)configureScrollView {

[self.contentView addSubview:self.contentArticle];
[self.scrollView addSubview:self.contentView];

CGRect frame = self.contentView.frame;
frame.size.height = self.contentArticle.contentSize.height;
self.scrollView.frame = frame;

[self.contentView sizeToFit];
[self.scrollView sizeToFit];

self.scrollView.contentSize = self.contentView.frame.size;
self.contentArticle.editable=NO;
self.contentArticle.scrollEnabled=NO;

 //enable zoomIn
self.scrollView.delegate=self;
self.scrollView.minimumZoomScale=1;
self.scrollView.maximumZoomScale=7;

I did so many changes, and im not sure what is going on in there anymore!...

help would be sooo nice :)

UPDATE-

- (void)configureScrollView {

[self.contentView addSubview:self.contentArticle];
[self.scrollView addSubview:self.contentView];

CGRect textViewFrame = self.contentArticle.frame;
textViewFrame.size = [self.contentArticle contentSize];
self.contentArticle.frame = textViewFrame;

[self.scrollView setContentSize:textViewFrame.size];
self.contentArticle.editable=NO;
self.contentArticle.scrollEnabled=NO;
}

screen shot of the View

1

3 Answers 3

3

Try

- (void)configureScrollView{

    self.contentView.autoresizingMask = UIViewAutoresizingNone;
    self.contentArticle.autoresizingMask = UIViewAutoresizingNone;

    CGRect textViewFrame = self.contentArticle.frame;
    textViewFrame.size = [self.contentArticle contentSize];
    self.contentArticle.frame = textViewFrame;

    CGRect contentViewFrame = self.contentView.frame;
    contentViewFrame.size.height = textViewFrame.origin.y+textViewFrame.size.height;
    self.contentView.frame = contentViewFrame;

    [self.scrollView setContentSize:contentViewFrame.size];

    self.contentArticle.editable=NO;
    self.contentArticle.scrollEnabled=NO;

    //enable zoomIn
    self.scrollView.delegate=self;
    self.scrollView.minimumZoomScale=1;
    self.scrollView.maximumZoomScale=7;

}

Source code

Sign up to request clarification or add additional context in comments.

5 Comments

I updated my question... part of the code really helped me, still the height of the scrollview doesn't fit, it remains the same. when I used your code, without changes, the textview started at the middle of the view... any idea?
@AndroAid If you are resizing your views programmatically, don't set autolayouts/autoresizing masks.If you are setting, set within the containerView You can refer to the source code provided.
I can't figure it out... I have a UIView, that contains a UIScrollView. the scrollView contains the contentView, which contains the textview. the autoResize subviews is checked in all the views. but still NADA. my project is almost done, and this is the last main issue :/
added screenshot of the problematic view :)
@AndroAid One reason I can think about is using the AutoLayout. The source code I provided don't use autolayout.
0

had same issue , tried to find solution for many days and finally i got it working. I have a textview inside a scrollview.

  1. disabled autolayout from storyboards
  2. ive added the textview to scrollview with addsubview
  3. and finally set the content of the scrollview, to the textview frame height.

Below my code:

_textView.text = stripped; //(some string ,yours: contentArticle)
[_textView sizeToFit];
CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.scrollEnabled = NO;
_textView.frame = frame;

[self.scrollView addSubview:_textView];
[self.scrollView setContentSize:CGSizeMake(320,frame.size.height)];

Hope it helps!

Comments

0

You need to set self.contentView height first Use this code:

- (void)configureScrollView {

    [self.contentView addSubview:self.contentArticle];
    CGRect frame = self.contentArticle.frame;
    frame.size.height = self.contentArticle.contentSize.height;
    self.contentArticle.frame = frame;

    [self.scrollView addSubview:self.contentView];
    frame = self.contentView.frame;
    frame.size.height += self.contentArticle.frame.height;
    self.contentView.frame = frame;

    self.scrollView.contentSize = self.contentView.frame.size;
    self.contentArticle.editable=NO;
    self.contentArticle.scrollEnabled=NO;

    //enable zoomIn
    self.scrollView.delegate=self;
    self.scrollView.minimumZoomScale=1;
    self.scrollView.maximumZoomScale=7;
}

1 Comment

thanks for the answer. as I wrote to Anupdas, the code seems right, but the text in the textview starts at the middle of the view. there's lots of scrolling until it gets to the text, and then the text cuts off in the middle.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.