iPhone: Freeform XIB file doens't fit in iPhone view
Question
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.
Solution
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....
OTHER TIPS
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