I am trying to create sample gallery before filling real data.
float xAxis = 0;
float mostHeight = self.galleryView.bounds.size.height;
for (int i = 0; i < 5; i++) {
//getImage from url
UIImage* myImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString: @"http://4.bp.blogspot.com/-M9k3fhlUwmE/TdYgxL97xMI/AAAAAAAAAY8/_r45zbAm1p0/s1600/CARTOON_Cat-full.jpg"]]];
myImage = [[MyMath sharedMySingleton] imageWithImage:myImage convertToSize:CGSizeMake(mostHeight - 10, mostHeight - 10)];
//set image
UIImageView *rview= [[UIImageView alloc] initWithImage:myImage];
/*adding the view to your scrollview*/
[self.galleryView addSubview:rview];
xAxis += myImage.size.width + 20;
}
//set scrolling area
self.galleryView.contentSize = CGSizeMake(xAxis, mostHeight);
galleryView is UIScrollView from xib. Here, i am trying to fill 5 same pictures to gallery, but it fills only one and space after that (because of xAxis number). What did i do wrong?
P. S. I am new in iPhone sdk, so don’t judge me
You never set the frame for the
UIImageView. You need to offset thexcoordinate of theoriginof theframe(frame.origin.x) by width of the image view + padding.