This is my 14th day of the August Blog Challenge. Check out the details: August Blog Challenge Shares some tips and tricks that XIB or Storyboard can use to make your development more efficient. In terms of impact, conflict, so specific development depends on the actual situation, and team requirements.

1. The storyboard is used

For some simple applications ordemoWe can do it atstoryboardTo quickly build simple logic

  • Adding a Navigation Controller

  • Add the Tabbar controller

  • Add a Tabbar child controller

  • Adding dependencies

  • Add three child controllers

  • Associated controller

2. StackView usage

We made stackView show that descLabel was constantly switching between show and hide when clicking a button



Let’s add abackgroundConvenient observation, after the DESC hidden or show

  • This way we can do a lot of things, such as a certain Cell of a certain controlShow and hide, will automatically changeThe refresh layoutLayout, for some complex situations we can even use nestedstackview. In fact, android or H5 pages have long had such controls, personal feelingstackViewCooperate withxibIt’s pretty easy to use.

For pages like seats, use them when you have limited timestackViewCan also meet the demand, of course, the final usecollectionView, more convenient to expand.

3. Use of UIScrollerView

  • Add scrollerView

  • Uncheck, do not use the systemcontentViewLayout.

  • Adding a CustomcontentView

  • Tip here we can set up our own content viewhighlyOr do you rely onThe proportionDebug.

  • This is the one up hereThe proportionAfter the height, below is the ratio. The height of the content view is 700+ current controller height *0.001, which is about 700. (If the current screen is greater than 700, it will be left blank.)

  • We add this constraint asattributeIs used to determine whether the current controllerIs greater thanOur default value is greater than thatThe screen height

  • For example, the following page has no complex logic, and the displayed page is used at this timexib, content view asscrollerViewIt was done in about a morning.

4. Xib uses nested XIBs

We reuse a lot when we’re developing code, but can we reuse a XIB? We create a View and choose custom dimensions.

  • Let’s add some controls and set the XIB size to 300-138

We select the current View Owner as our testView instead of View inheritance.

Let’s wire this view as mainView and add a property variable.

  • And then we know that it happens when xiB loadsinitWithCoderMethod call, which is primarily the current viewaddView of xiB, same size.
-(instancetype)initWithCoder:(NSCoder *)coder

{

    if (self = [super initWithCoder:coder]) {


        self.bounds = CGRectMake(0.0.300.138);

        [[NSBundle mainBundle]loadNibNamed:@"testView" owner:self options:nil];

        self.mainView.frame = CGRectMake(0.0.300.138);

        [self addSubview:self.mainView];


    }

    return self;

}
Copy the code

The effect

5. To summarize

Some people don’t like using XIBs, but it’s worth knowing. It’s much more efficient for individuals or small teams, and it’s fine for subsequent iterations or modifications. Some page display or simple logic using XIB can improve efficiency, personal feeling seems more readable after all visual. A small company is responsible for several projects, soon finished 😂.