Horizontal UIScrollView inside custom UITableViewC

2020-01-28 05:50发布

The main goal is to be able to scroll each row's content horizontally.

I'm trying to do this with X Code 5 and using StoryBoard.

The problem seems to be simple, but after many hours of searching I got nothing except for one problem that is somewhat similar but using programatic only approachsee here.

In IB, I have the structure as shown in the design below. View structure

  • The content size of the scrollview in set to {5000, 500} set both in IB and in code
  • The scrollview frame is {0,0}{320,44}
  • The labels frame is set to {20,0}{500,44}

I've also provided an example project in a github repository. The example also includes a "normal" scrollview working outside of a uitableviewcell.

Please say that I overlooked something very basic.

8条回答
老娘就宠你
2楼-- · 2020-01-28 06:14

I had the same problem, and found that removing the scrollview's content view and adding it again works:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.label removeFromSuperview];
    [self.scrollView addSubview:self.label];
    self.scrollView.contentSize = self.label.frame.size;
}

It's not the most elegant solution, but it works for me.

查看更多
时光不老,我们不散
3楼-- · 2020-01-28 06:16

Another alternative for this is to use UICollectionView inside a custom UITableViewCell

查看更多
登录 后发表回答