how to create many elements in Interface Builder t

2019-07-08 08:35发布

问题:

I have a UIView where has so many elements like Text Field, Date Picker, and Picker View to add data to my app. This won't make it in a screen in Interface Builder. In my mind, user will scroll down to insert them. Is there a way to achieve this?

Thanks

回答1:

How to setup a view in Interface Builder that is taller than 480 pixels.

This will be done using two xib files:

MainView.xib is the view for MainViewController, it is 460 pixels tall.
TallView.xib is a 600 pixel tall view (see below for how to do this in IB).

MainViewController only contains a UIScrollView. All your content should be in TallView.xib

In MainViewController, override viewDidLoad and use the following code:

viewDidLoad:

- (void)viewDidLoad {

    //load your TallView.xib into a UIView object
    NSArray *nibParts = [[NSBundle mainBundle] loadNibNamed:@"TallView" 
                                                      owner:nil 
                                                    options:nil];
    //first object is the view
    UIView *tallView = [nibParts objectAtIndex:0];

    //add tallView to scrollView 
    [scrollView addSubview:tallView];

    //set content size to same dimensions as TallView.xib
    scrollView.contentSize = CGSizeMake(320, 600);
}

How to create a view taller than 480 pixels in Interface Builder

Override the height of a xib beyond 480 by first setting the simulated interface elements to "none", and then change the height.

See two screen shots: alt text http://static.benford.name/IBViewAttributes.png

alt text http://static.benford.name/IBViewSize.png



回答2:

AFAIK this is not the standard behaviour for iPhone application. You can create tableView with names of properties and show some other view(with datePicker ot textFields) to enter value when the user clicks the row of the table.



回答3:

I'd suggest a UIScrollView. I'm not quite sure if it will do everything that you need to do, but it's worked for me when I needed to have a scrolling view.