When to use InterfaceBuilder to create views?

Going through extensive online documentation and various code examples in the dev center, I am puzzled. Apple recommends ALWAYS use IB when creating your views, and yet in many code samples, views are completely generated by the code (initialized in the loadView method for viewController). Is there a “best practice” when you should use IB rather than code to create your views?

+3
source share
8 answers

There are no hard and fast rules, but in general, the more complex the view, the more I will use IB. Very simple things like TableView in NavigationView will almost always be in code. More complex layouts, such as a detailed view with dozens of output labels, will usually be posted in IB.

However, if for some reason I do not want to include XIB in the final product, for example, if it is for a static library, I will start with IB, and then use NIB to convert the code .

+2
source

Personally, I would recommend creating views using only code. This gives you an incredible amount of control over the appearance of all objects in the view and makes objects much easier to access when events are fired or answers are needed.

- IB , . .

+1

iPhone: Big Nerd Ranch

, . subviews, XIB (.. Interface Builder).

+1

- IB . , , , , ([myView size].height/2 + 15)% 3 .

+1

Interface Builder. , IB .

+1

, , IB - . , .

, - , .

,

0

. IB , .

, , /... . /nibs vs programatic, OpenGL (iPad/iPhone). , IB ...

0

Interface Builder. -, , UILabels . , UILabels , , , . Interface Builder .

In general, if you have a variable number of subzones or the positions of subzones may vary based on your data, use Objective-C instead of Interface Builder.

0
source

Source: https://habr.com/ru/post/1751575/


All Articles