luca
luca

Reputation: 37146

Change UIView to UIScrollView

I built in my storyboard this "myView" view controller scene:

enter image description here

I have a simple view containing an ImageView and a UILabel (that I reference in code through IBOutlets).

What I want is transform this view to a scrollview and I was wondering if I could just adjust things in the storyboard for this purpose.

I also tried to change the view to scrollview programmatically adding to the viewController's "ViewDidLoad" method the following:

CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
scrollView.contentSize=CGSizeMake(320,600);


self.view=scrollView;

But I'm not able to see my imageView and my label if I do So..Why? I also tried (in storyboard) to assign the view (inside the "custom class" panel) the UIScrollView class but that's not working.

Upvotes: 3

Views: 4906

Answers (2)

luca
luca

Reputation: 37146

OK I found the solution, I changed the view type (identity inspector), but the view property of a UIViewController isn't a UIScrollView. So I get round this with casting the view to a UIScrollView:

[(UIScrollView *)self.view setContentSize:CGSizeMake(320, 1000)];

Upvotes: 2

ADK
ADK

Reputation: 139

Add View to controller->Identity Inspector->Class-Change to UIScrollView

Resize your view (self.urview as! UIScrollView).contentSize = CGSizeMake(self.view.frame.width, self.view.frame.height)

Upvotes: 1

Related Questions