Image to Scroll with ScrollView- Interface Builder?
Please excuse all the questions all at once today! (And I'm sure I will feel like a fool when I get the answer to this one...)
I am trying to build some simple views containing images (png files) and text. I have been using Interface Builder, adding scrollview to the main view and adding the images and text as subviews... but when I build-and-go only the text view area of the screen can be scrolled.
I have viewed several tutorials about Scrollview, and the only thing I've noticed that's different from what I've been doing differently is that in each of the IB tutorials another view (an unnecessary view that doesn't get used for anything) is created. Why is that? And is it really necessary?
**I am NOT wedded to using Interface Builder. I was hoping to use it because I will have to build several views like this, and I thought it might make it faster. But, if you know of a way to do this programmaticaly, that would also be helpful.
where, of course, you should use the dimensions of the content that is being scrolled.
Thank you for your reply here. If I do this programmatically, and I set the contentSize of the scrollview- I would then add the image and text as subviews?
You can still add your images and other subviews in Interface Builder. However, measure the size of your content in IB and input that information in the line of code I posted before. You can do this by making your IB window really big so that you can see all the content at once and then recording the size of the window.
Add a scroll view to your view in IB. Add all the images/subviews that you want to the scroll view. Now size the scroll view so that it is big enough to contain _all_ of those images/subviews. Hit cmd+3 and note the width and height of the scroll view. Then resize the scroll view to the actual size you want.
Go in your code and use the snippet I posted before in the viewDidLoad method:
Add a scroll view to your view in IB. Add all the images/subviews that you want to the scroll view. Now size the scroll view so that it is big enough to contain _all_ of those images/subviews. Hit cmd+3 and note the width and height of the scroll view. Then resize the scroll view to the actual size you want.
Go in your code and use the snippet I posted before in the viewDidLoad method: