Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIViewContentModeScaleAspectFit not working for UIScrollView subview UIImageView

For hours I've been trying to figure out why the UIScrollView won't display the images from a NSMutableArray.

I realized the uiimageview objects are in the subview collection inside the UISCrollview but somehow the UIViewContentModeScaleAspectFit is ignored... How can I fit to scale then?

please, any tips?

- (void)viewDidLoad
{
    [super viewDidLoad];

    BookDalc* bookDalc = [[BookDalc alloc] init];

    NSMutableArray* books = [bookDalc FindByIconID:IconID];

    for(int i = 0;i<books.count;i++)
    {
        CGRect frame;
        frame.origin.x = self.scrBook.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrBook.frame.size;

        UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
        subview.contentMode = UIViewContentModeScaleAspectFit;

        BookEntity *currentModel = [books objectAtIndex:i];
        UIImage *currentImage = [currentModel TheImage];

        subview.image = currentImage;
        [self.scrBook addSubview:subview];
    }
    self.scrBook.contentSize
    = CGSizeMake(self.scrBook.frame.size.width * books.count, self.scrBook.frame.size.height);
}
like image 521
RollRoll Avatar asked Dec 08 '25 06:12

RollRoll


1 Answers

The frame of self.srcBook might not be set.

For more information read this answer. Why am I having to manually set my view's frame in viewDidLoad?

like image 158
Pierre-Loup Avatar answered Dec 09 '25 20:12

Pierre-Loup



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!