Adding views. Storyboard VS. Program

I struggled with this for a long time. Suppose I have a UIViewController, and you need to place a UIImageView with a UIImage in this controller. Therefore, I have two ways to do this:

1.) Through the storyboard

2.) UIImageView *imageView = [UIImageView new]; imageView.frame = CGRectMake(bla, bla, bla); [self.view addSubview: imageView];

I also need to support different screen sizes (from iPhone 4 to iPhone6 โ€‹โ€‹+), and autostart with restrictions is not completely clear to me. And I sh * tcoding like

int wrapperHeight = (screen.height == 480) ? 100 : 200

I feel like I'm doing something wrong. When I started learning objective-c, I saw some open source projects, and there wasnโ€™t a storyboard at all, so I thought adding views programmatically was good practice.

Could you explain the โ€œright wayโ€ to me?

+4
source share
2 answers

I would say that most of the time storyboards with autorun are the best choice. It has several advantages:

  • Separates presentation from logic. Creating an entire interface in a controller is usually a bad design. And for simple interfaces declaring them in an imperative order, there is a lot of overhead. Very often, you get hundreds of lines of code for an interface that could be done in a storyboard or xib in 10 minutes without any effort.

  • WYSIWYG, , . , , 4 iPhones + 2 iPads . .

  • Autolayout. , , Apple . , , ~ 80% . 20% - - , .

  • . , , , , . - , .. iPhones iPads.

, - . , , . , , , . xib , .

, . , , ( ), , . . .

, . . , , . " ", , iPhone (4 ), . , , . - . Autolayout :)

, , xibs : http://www.raywenderlich.com/51992/storyboards-vs-nibs-vs-code-the-great-debate p >

(http://www.raywenderlich.com) , .

+8

, , , , , /xib,

-

  • . , .

  • , IB.

-

  • storyBoard, , , , , ..

  • , , .

  • , , , , .

, , , , , , , , ,

, XIB , .

+3

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


All Articles