Discussion on iOS creation interface method

Source: Internet
Author: User

In the past, when I was getting started, the demo I had written on the starter books was based on the storyboards-drag interface. Later contact with the company project, found that the interface is pure code to write complex AutoLayout. Then, the leader sent me a masonry library to see, still is the handwriting code layout interface, but the efficiency is much higher. Work for a period of time, read a lot of blogs, also read some books, found that with a pure code to write the interface is very few, so on Google search storyboards what the benefits, and finally found a very good article. Refine some of the ideas in this article, and also express your point of view.

Article link: IOS User interfaces:storyboards vs. NIBs vs. Custom Code

(Https://www.toptal.com/ios/ios-user-interfaces-storyboards-vs-nibs-vs-custom-code)


This paper introduces three kinds of methods of building interface, and discusses the advantages and disadvantages of different methods respectively.

In fact, for these several methods, there is no best, only the most suitable.

The summary is that storyboards is an easy-to-observe and easy-to-use IOS UI design tool. It also eliminates the fixed creation of the control's template code, but leads to a lack of significant flexibility. NIBs provides a lot of flexibility for single view, but there is no visual flow (personal guessing is the switch of the view controller). The most flexible solution is the pure code layout, but the pure code is not so intuitive, nor so easy.

The same topic, in the previous article Tang Qi teacher, also discussed this issue: IOS development controversy (II)

One of the more convincing sections is that he analyzed the number of xib files included in more than 100 apps, presumably speculating that most of the interfaces in many famous apps are handwritten.

At the same time, he also made his own suggestions:

1, for the complex, dynamically generated interface, it is recommended to use the manual programming interface.

2. For buttons or UI controls that require a uniform style, it is recommended to use manual code to construct them. Convenient for subsequent modification and reuse.

3. For UIView classes or Uiviewcontroller classes that require inheritance or combination of relationships, it is recommended to manually write the interface in code.

4, for those simple, static, non-core functional interface, you can consider using Xib or storyboard to complete.

At the end of the line, I personally prefer to use purely code layouts, not because I've always done this, but for the following reasons:

1, pure code layout Most people are criticized is the code is too large, indeed, I used autolayout when each write a constrains will be several lines of code, a control has a few constraints to write a few constrains, this code to go up the amount of a bit. But now there is open source masonry library, for Swift also has corresponding library, so for the code volume and learning difficulty, the pure code layout This part of the flaw can be fully compensated.

2, pure code to write the interface easy to control, this easy to control is that you add a control, a constraint in the code can be very intuitive to display, because each line of code to write your own will be very clear. And for storyboards, the control's property interface is a big chunk, whether you change it or not, the data is displayed there, and sometimes you forget to change what you're going to find in the property bar. For example, I changed the background color of the view from Graycolor to Lightgraycolor, and I can see this sentence intuitively from the code view.backgroundcolor = [Uicolor Lightgraycolor], but if Storyboards, I'm going to look for the background color of this column, but also to distinguish between gray and light gray.

3, finally, is the code reuse. For example, to write a complex Tableviewcell, using storyboards to drag the interface, you will see a bunch of controls and layout on the view, if I want to reuse this cell and make some layout changes, I have to drag and drop, if there is a response to the event, Also need to re-connect to the new class, think about this workload, not error is difficult. For the handwriting interface, write a control is encapsulated in a class, need to reuse, inherit or copy paste to another project can be used, even if there is a response to the event, write a few protocol to do feedback to solve.

4, the most finally, I remember to go to school to engage in MFC, then there is a discussion of the handwriting interface or drag interface, at that time a very persuasive comment is that the handwriting interface can exercise your understanding of MFC programs, you may still not know the MFC implementation principle, but you will be very familiar with MFC The implementation process (presumably this means). This I think is also applicable on IOS. For example, the button event, with storyboards is a mouse drag, even a line out, the system generated an event code, and you just fill in the code can. I think it's not a good thing to learn about iOS, although I'm not very familiar with the implementation of iOS at the bottom, but by manually adding events through the handwriting interface, I know how these things are added, what the relationship between the additions and other classes is. So the handwriting interface has some help with learning IOS.

Discussion of the iOS creation interface method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.