How to add in an background image in a scroll view image?

The problem is that you are using page when you are create the frames for the background views and then not resetting it when you start creating the frames for the images. Page will have a value of 3 going into the for loop for the imgArray, making it place it at a 4th index.

Up vote 2 down vote favorite share g+ share fb share tw.

I will like to add in a background image bgImageView. Image = UIImage imageNamed:@"frame_trans"; for each image in the scrollview, however the scroll view expand instead of adding the image behind each image, what have I do wrong? EDIT: working code added, thanks to ColdLogic.

This is my old scroll view I wanna add in a paperclip but the current code do this. CODE: //init scrollview in location on screen //scrollview = UIScrollView alloc initWithFrame:CGRectMake(30, 100, 278, 290); //scrollview. BackgroundColor = UIColor redColor; //pass image filenames NSMutableArray *fileNames = Info.

ImageFiles; //NSMutableArray alloc init autorelease; //setup the array of uiimageviews NSMutableArray *imgArray = NSMutableArray alloc init; NSMutableArray *bgImgArray = NSMutableArray alloc init; //loop through the array imgNames to add file names to imgArray for (NSString *imageName in fileNames) { NSString *tempIMGName = NSString stringWithFormat:@"data/%i/%@",Info. ID, imageName; NSLog(@"tempIMG %@",tempIMGName); UIImageView *imageView = UIImageView alloc init; UIImageView *bgImageView = UIImageView alloc init;; imageView. Image = UIImage imageNamed:tempIMGName; bgImageView.

Image = UIImage imageNamed:@"frame_trans"; imageView. ContentMode = UIViewContentModeScaleAspectFit; CGAffineTransform newTransform = CGAffineTransformMakeRotation((CGFloat)(-3 * M_PI / 180.0)); imageView.layer. AffineTransform = newTransform;//CGAffineTransformMakeRotation(degreesToRadians(10)); imgArray addObject:imageView; bgImgArray addObject:bgImageView; imageView release; bgImageView release; } CGSize pageSize = scrollview.frame.

Size; NSUInteger page = 0; for (UIView *bgViewForScrollView in bgImgArray) { scrollview addSubview:bgViewForScrollView; bgViewForScrollView. Frame = CGRectMake(pageSize. Width * page++ +10, 0, pageSize.

Width -20 , pageSize. Height); // making use of the scrollView's frame size (pageSize) so we need to; // +10 to left offset of image pos (1/2 the gap) // -20 for UIImageView's width (to leave 10 gap at left and right) } NSUInteger page1 = 0; for (UIView *viewForScrollView in imgArray) { scrollview addSubview:viewForScrollView; viewForScrollView. Frame = CGRectMake(pageSize.

Width * page1++ +10, 0, pageSize. Width -20 , pageSize. Height); // making use of the scrollView's frame size (pageSize) so we need to; // +10 to left offset of image pos (1/2 the gap) // -20 for UIImageView's width (to leave 10 gap at left and right) } //add scroll view to view self.

View addSubview:scrollview; self. View bringSubviewToFront:scrollview; scrollview. ContentSize = CGSizeMake(pageSize.

Width * imgArray count, pageSize. Height); //scrollview. ContentSize = CGSizeMake(320 *viewcount + 20, 290 ); scrollview.

ShowsHorizontalScrollIndicator =NO; scrollview setPagingEnabled:YES; scrollview. Delegate =self; iphone ios uiscrollview uiimageview link|improve this question edited Dec 3 '11 at 7:18 asked Dec 2 '11 at 16:14Desmond248213 94% accept rate.

I don't understand your question or problem. Please attempt to clarify. – ColdLogic Dec 2 '11 at 16:24 thanks for the reply coldlogic, added picture to clarify – Desmond Dec 2 '11 at 16:45.

The problem is that you are using page++ when you are create the frames for the background views and then not resetting it when you start creating the frames for the images. Page will have a value of 3 going into the for loop for the imgArray, making it place it at a 4th index. For (UIView *bgViewForScrollView in bgImgArray) { //code } //ADD THIS LINE OF CODE page = 0; for (UIView *viewForScrollView in imgArray) { //Code }.

OMG, thanks for the help Coldlogic.......... how I wish I can up your rep more :) – Desmond Dec 3 '11 at 7:16.

You should be adding the background number images to the scrollview and to each of them adding a subview for the paperclip image. BgImageView addSubview:imageView.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions