Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Inside myscrollview there are multiple objects of uiimageview each with image.
contentSize of myscrollview depends on the number of desings * width of each imageview.

how to set the constraints for imageview inside the myscrollview for landscape and portrait mode also the myscrollview is not scroll to show to different images

below is my code for the cellForRowAtIndexPath of
UITableView


//.//
myscrollview = nil;
myscrollview = [[UIScrollView alloc] init];
myscrollview.backgroundColor = [UIColor greenColor];
myscrollview.decelerationRate = UIScrollViewDecelerationRateFast;
myscrollview.delegate = self;
myscrollview.pagingEnabled = true;
myscrollview.scrollEnabled = true;
myscrollview.bounces = false;
self.tableView.scrollEnabled = false;
myscrollview.contentSize = CGSizeMake(tableView.frame.size.width * designList.count, cell.frame.size.height);

for (int i = 0; i < designList.count; i++)
{
UIImage *image = [self getImage:i];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[myscrollview addSubview:imageView];

[myscrollview setTranslatesAutoresizingMaskIntoConstraints:NO];
[imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
NSDictionary * viewDictionary = NSDictionaryOfVariableBindings(cell,myscrollview,imageView);
[myscrollview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView(==myscrollview)]" options:0 metrics:nil views:viewDictionary]];
[myscrollview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageView(==myscrollview)]" options:0 metrics:nil views:viewDictionary]];

}

[cell.contentView addSubview:myscrollview];

//.//setting the constraints
[cell.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
[myscrollview setTranslatesAutoresizingMaskIntoConstraints:NO];

NSDictionary * viewDictionary = NSDictionaryOfVariableBindings(cell,myscrollview);

[cell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[myscrollview(==cell)]" options:0 metrics:nil views:viewDictionary]];
[cell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[myscrollview(==cell)]" options:0 metrics:nil views:viewDictionary]];
//..//
Posted
Comments
KarstenK 13-Nov-14 4:55am    
consider using different cells with different layout => reload on rotation

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900