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];

}
0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
user1898829
  • 3,437
  • 6
  • 34
  • 62

3 Answers3

2

Add this:

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

Should work :-)

DD_
  • 7,230
  • 11
  • 38
  • 59
  • 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,266
  • 1
  • 23
  • 29
0

Set scrollview contentmode aspectfill.

Girish
  • 4,692
  • 4
  • 35
  • 55
Monish Bansal
  • 509
  • 3
  • 15