iOS 개발 시 StoryBoard (스토리보드) 없이 프로젝트 생성하기

개발/iOS 2017. 10. 27. 01:10
반응형

요즘 xcode는 프로젝트를 생성하면 스토리보드를 무조건 생성하게 됩니다. 이런 스토리 보드를 제거하여 개발 할 수 있는 방법을 알아보도록 하겠습니다.


스토리보드는 작은 노력으로 화면 이동/전환이나 사용방법이 간단하다는 장점이 있으나 여러사람이 개발 할 때 형상관리(SVN)에서 문제가 자주 발생하게 됩니다. 그래서 프로젝트 규모가 커지면 스토리보드 없이 개발하는게 훨씬 좋다고 보여집니다. 실제로 금융 등 약간 규모가 있는 프로젝트를 진행 시에는 스토리 보드를 잘 사용하지 않습니다. 


1. 프로젝트 생성

"Create a new  Xcode project" 선택하여 프로젝트를 생성합니다.

"iOS" 탭에 "Single View App"을 선택하여 Next를 눌러 줍니다.



Product Name 과 Team 을 선택해 줍니다. 



2. 스토리보드 제거하기

이미지와 같이 Info.plist에서 "Main storyboard file base name" 항목을 삭제 해줍니다. - 버튼을 눌러 삭제하거나 Del 키를 눌러 삭제할 수 있습니다.



storyboard 파일도 삭제 해주세요. "Main.storyboard" 파일을 삭제하시면 됩니다.



3. 코드 작성

이제 설정은 완료 되었고 AppDelegate의 UIWindow에 ViewController를 연결 해주면 작업이 완료됩니다.


AppDelegate.m 수정

상단에 Import 하기.

1
#import "ViewController.h"
cs


처음 실행 시 호출 되는 application:didFinishLaunchingWithOptions: 메소드 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    ViewController *con = [[ViewController alloc] initWithNibName:nil bundle:nil];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    self.window.rootViewController = con;
    [self.window makeKeyAndVisible];
    
    return YES;
}
cs


ViewController.m 수정

화면이 뜰때 라벨을 하나 붙여서 보여주기 위해 작성해 봅시다. 확인 겸 해보는 것으로 꼭 하지 않아도 됩니다.

1
2
3
4
5
6
7
8
9
10
11
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(50100200200)];
    [lab setText:@"라벨!!"];
    [lab setBackgroundColor:[UIColor brownColor]];
    [lab setTextColor:[UIColor whiteColor]];
    [lab setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:lab];
}
cs



4. 결과화면


이상 프로젝트 생성시 스토리보드를 제거하는 방법에 대해 알아 보았습니다. 쉽죠!?

아래 링크로 샘플 프로젝트를 다운받아 직접 확인해 보세요.

SampleApp.zip


프로젝트 생성된 Xcode 버전 :  Xcode 9.0.1 (9A1004)



반응형
admin