0

Sorry for my english firstly. I have an image and a text which are both must be scrolled.But they don't. So here i have a piece of my code,where i've trying to do what i need to:

self.newsBody.text = [self bodyWithoutTags:self.newsContent];
NSData *imgData = [ServerRequest getImgFromServer:self.newsImage];
UIImage *img = [UIImage imageWithData:imgData];
self.scrollView.contentSize = CGSizeMake(320, 225);
self.newsImageView.image = img;
self.newsImageView.contentMode = UIViewContentModeScaleAspectFit;
self.newsImageView.clipsToBounds = YES;;
self.newsImageView.frame = CGRectMake(0, 0, 320, 204);


self.newsBody.frame = CGRectMake(0, 202, 320, 225);


self.newsBody.clipsToBounds = YES;
self.newsBody.autoresizesSubviews = YES;

self.newsBody.scrollEnabled = NO;
[self.scrollView addSubview:self.newsImageView];
[self.scrollView addSubview:self.newsBody];

Thank you for help!

  • Are you using Autolayout for the ScrollView? – chris13 Mar 13 '14 at 07:14
  • [link](http://stackoverflow.com/users/1501218/chris13) yes,i use that – user3414050 Mar 13 '14 at 07:17
  • I'm not what's really the problem - I usually don't use Autolayout - but maybe [this](http://stackoverflow.com/questions/13499467/uiscrollview-doesnt-use-autolayout-constraints/13548039#13548039) will help you. – chris13 Mar 13 '14 at 07:33

1 Answers1

0

Your real content size ...

self.newsImageView.frame = CGRectMake(0, 0, 320, 204);
self.newsBody.frame = CGRectMake(0, 202, 320, 225);

... is 320 x ( 202 + 225 ), which is 320 x 427. But you do set scroll view's content size to ...

self.scrollView.contentSize = CGSizeMake(320, 225);

... which is actually wrong. Scrolling is done when you do set correct content size and content size is bigger than scroll view itself. Otherwise it's not scrolling, no need to scroll if your content is smaller than scroll view itself.

zrzka
  • 20,249
  • 5
  • 47
  • 73