1

AspectFill doesn't work so well with ScrollView.

This is my code

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat pageWidth = self.scrollView.bounds.size.width;
    int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    self.pageCount= page;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.scrollView.frame.size.width * self.pageCount, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
    [imageView setImageWithURL:[self.urlArray objectAtIndex:self.pageCount] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    [imageView setContentMode:UIViewContentModeRedraw];
    [self.scrollView addSubview:imageView];

}
noob
  • 18,447
  • 20
  • 113
  • 179
user1898829
  • 3,287
  • 6
  • 31
  • 58

3 Answers3

2

Add this:

[scrollView setContentMode:UIViewContentModeScaleAspectFit];
[imageView sizeToFit];

Should work :-)

DD_
  • 7,401
  • 11
  • 37
  • 61
  • Made some images really small and in some cases one could see multiples of the same image on the scrollview – user1898829 Mar 06 '13 at 12:32
  • your images may be of different sizes! maintain a common size ratio for all the entries in scrollview – DD_ Mar 06 '13 at 12:34
  • I'm getting the photos from flickr so I need to somehow resize them without stretching them. – user1898829 Mar 08 '13 at 07:15
  • Resizing is quite simple, you can use a common method and pass each of your image before adding to the scrollviewarray, see this [method](http://stackoverflow.com/a/4712537/1756131) – DD_ Mar 08 '13 at 07:25
0

I believe your scroll view has autoresizesSubviews enabled, disable it and your images will appear (and the default view mode for images should be just fine)

Ege Akpinar
  • 3,216
  • 21
  • 29
0

Set scrollview contentmode aspectfill.

Girish
  • 4,692
  • 4
  • 34
  • 54
Monish Bansal
  • 499
  • 3
  • 15