Почему бы не использовать UIScrollView? Если мне когда-нибудь понадобится сложить изображения рядом, я просто сделаю это на UIScrollView. Код выглядит примерно так
//Let's say your UIScrollView is named 'scrollView' and the array containing your UIImages is called 'imageArray'
CGFloat contentWidth = 0;
for(UIImage *thisImage in imageArray)
{
UIImageView *thisImageView = [[UIImageView alloc] initWithFrame:CGRectMake([imageArray indexOfObject:thisImage]*(thisImage.size.width + PADDING_IF_ANY), 0, thisImage.size.width, thisImage.size.height)];
[scrollView addSubview:thisImageView];
[thisImageView release];
contentWidth += thisImage.size.width + ([imageArray indexOfObject:thisImage]==0)?0:PADDING_IF_ANY;
}
scrollView.contentSize = CGSizeMake(contentWidth, scrollView.frame.size.height);
Объяснение кода:
PADDING_IF_ANY означает требуемый отступ между двумя изображениями. Код - это просто цикл for, который циклически перебирает ваш массив UIImage, выделяет UIImageView для каждого изображения и устанавливает X-origin на основе позиции индекса UIImage в массиве.
Следовательно, индексная позиция 0 будет размещена в самой левой позиции в представлении прокрутки. Позиция индекса 1 будет установлена на 1 * (ширина изображения + отступ), то есть справа от предыдущего изображения в просмотре прокрутки и т. Д.
Чтобы использовать scrollView в UITableViewCell, сделайте это в cellForRowAtIndexPath:
//This line gets you the frame of the cell relative to the tableview.
CGRect cellFrame = [tableView rectForRowAtIndexPath:indexPath];
//Set the Y origin to 0. This will get you the frame for the scrollView to be added with to the cell.
cellFrame.origin.y = 0;
//Now add your scrollView
scrollView = [[UIScrollView alloc] initWithFrame:cellFrame];
/*
Do stuff
*/
[cell.contentView addSubview:scrollView];
[scrollView release];