1

I have created XIB file in freeform size because I need many controls to add. I have done it but when I push my view controller, it doesn't have automatic scrollbar on iPhone display and my view gets cropped! How to get my full view displayed on iPhone?

I have set view frame on view load but that doesn't make any difference!

- (void)viewDidLoad
{
     [super viewDidLoad];
     [self.view setFrame:CGRectMake(0, 0, 320, 600)];
}

Following looks like cycling between view and scrollview worked for me! Not a good solution though!

- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = CGRectMake(0,0,320,600);
[self.view setFrame:frame];
self.scrollview = [[UIScrollView alloc] initWithFrame:frame];
[self.scrollview setBackgroundColor:[UIColor blackColor]];
[self.scrollview addSubview:self.view];
self.scrollview.contentSize = frame.size;
self.view = self.scrollview;
}

Thanks.

Paresh Masani
  • 7,474
  • 12
  • 73
  • 139

2 Answers2

1

You have to take different approach for this case.

You need to add a UIScrollView to your controller's view - make it take the whole screen and then inside the scroll view you can add as much content as you wish - this way your form will be scrollable and the user can go up and down to see all the controls inside the form

Marin Todorov
  • 6,377
  • 9
  • 45
  • 73
  • No I tried that it didn't work either! :( I always write code in ViewDid load but this time I have created controls in XIB file and don't know how to show it now! We never create UIScrollView while creating controls from code but it still works. Isn't it? – Paresh Masani Feb 13 '12 at 19:00
1

You should take a look at UIScrollView. Within the UIScrollView add a UIView for your content. You then need to set the content size of the UIScrollView to enable scrolling.

Example:

CGRect frame = CGRectMake(0,0,320,600);
UIView *subView = [[UIView alloc] initWithFrame:frame];

// Add objects to view

[self.scrollView addSubview:subView];
self.scrollView.contentSize = frame.size;

Hope this helps....

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
Nate Lyman
  • 94
  • 5