Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal UIScrollView inside custom UITableViewCell - using IB Storyboard - Not scrolling

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.

like image 348
marco alves Avatar asked Oct 04 '13 15:10

marco alves


People also ask

How to scroll the view in Storyboard?

You can scroll the scrollview in the Storyboard / Interface builder! Select the view inside scrollview in Document Outline, then scroll using your mouse or trackpad, you can see the view move. You should see the view controller elongated to 1100 pt height now.

How to make UIView scrollable?

You cannot make a UIView scrollable. That's what UIScrollView is for. However if you are using storyboards you can try to add constraints to the view so when you rotate the device the content remains inside the viewable area.

How to use scroll view in Uikit?

If the view you are looking at has its height set by the contents, then you only need to select your stack View, then click editor, then embed in, then Scroll View. Then do steps 4 -8, skip 6, and for 7 skip the height constraint because it is set by the contents.


2 Answers

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

like image 172
marco alves Avatar answered Oct 04 '22 21:10

marco alves


Autolayout is activated (and that's a good thing) in your storyboard. The scrollable size of a UIScrollView is computed based on the constraints of its subviews.

So you need to add "top, bottom, leading, trailing space to superview" on the UIImageView inside the UIScrollView. They can be all set to 0.

Now if you don't add any constraint to the UIImageView then its intrinsicContentSize size will be used.

Your constraints should look like this:

autolayout constraints

Note that you were also missing constraints on the content view of your cell.

When you're done with the constraints, remove all the setContentSize: calls from your code.

like image 41
Alexis Avatar answered Oct 04 '22 21:10

Alexis