Omar Freewan
Omar Freewan

Reputation: 2678

UIScrollView the subviews added but can not slide to them

- (void)viewDidLoad
{
MyData *data = [MyData SharedData];

scrollerView.pagingEnabled = YES;
scrollerView.bounces = YES;

int numberOfViews = [data.placePhotos count];
for (int i = 0; i < numberOfViews; i++) {

    CGFloat yOrigin = i * self.view.frame.size.width;
    UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
    awesomeView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300 , 320)];

    NSString * photourl = [[data.placePhotos objectAtIndex:i] stringByReplacingOccurrencesOfString:@"150x75" withString:@"440x440"];

    [imageView setImageWithURL:[NSURL URLWithString:photourl]];
    [awesomeView addSubview:imageView];

    [scrollerView addSubview:awesomeView];
    awesomeView = nil;
    imageView =nil;
}

I added the UIScrollView in the .xib file , when i tried to pull the scroll view from left to right it does not move, i have 4 subviews added but why i can not view them ?

Upvotes: 0

Views: 177

Answers (2)

Kai Huppmann
Kai Huppmann

Reputation: 10775

add scrollerView.contentSize = CGSizeMake(yOrigin + self.view.frame.size.width, scrollerView.frame.size.height); after the loop (even though I'm a little bit confused about why the x-origin is called yOrigin in your code...)

Upvotes: 0

mhunturk
mhunturk

Reputation: 296

you should set the content size the scrollView

     [self. scrollerView setContentSize:CGSizeMake(320, 1000)];

Give your width and heigth.

Upvotes: 1

Related Questions