ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Mac] Xcode로 아이폰 HelloWorld 앱 만들기!
    Mac 2016. 2. 12. 16:07


    아직 미약한 부분이 많으나, 정리를 차곡차곡 하면서 배워야하기에 시작해보도록 하겠습니다.


    초기 Helloworld 부터.




    진행하시기 전에, App Store에서 Xcode를 설치하신 후 진행하세요.




    아래는 xcode 첫 실행화면 입니다!


    라이센스 동의에 관해서 약관이 나왔으니 'Agree'









    간단하게 설치를 진행합니다.








    이렇게 첫 화면이 구성지는데 아래


    'Create a new Xcode project' 클릭







    여기서 자동적으로 초기 iOS 탭의 Application으로 잡혀있습니다.


    저희는 간단하게 문구 하나를 띄우는 것이므로,


    Single View Application 선택 후 Next






    Project Name, Organization identifier, Language, Device 등을 설정하는 화면입니다.


    설정하시고 Next






    아래 화면에서는 소스파일 경로를 지정하는 곳입니다.


    스샷이 엉뚱한게 찍혔으나, 저는 도큐먼트에 폴더를 생성하여 저장시켰습니다.








    경로까지 설정하고나면 아래처럼 첫 화면이 나옵니다.


    여기서 왼쪽 프로젝트 트리에서 main.storyboard 클릭








    소스 트리(Project Navigator) 왼쪽 칸에 보면 'View Controller Scene' 이 있습니다.


    보시면 'View Controller', 'First Responser', 'Exit'


    이렇게 3 개의 층(?)으로 구성되어 있네요.


    아직 공부를 더해야 하지만, 저희가 작성할 helloworld는 View Controller에 위치합니다.







    아래 화면은 가장 우측의 레이어입니다.


    이 레이어의 가장 하단에서 3번째 아이콘(Show the Object library)를 클릭해서 


    아래와 같이 label을 검색합니다. 


    이 검색된 label을 UI가 그려진 곳에 Drag & Drop 해서 가운데 위치시킵니다.







    아래처럼 가운데 위치시켜놓습니다. 위치 시킨 후, 더블 클릭하여 문자를 helloworld로 변경합니다.







    그 다음, 아래 화면에서 iPhone 5s 부분을 클릭해서 원하는 시뮬레이터 기기에서 테스트 하기위해


    선택합니다.





    저는 iPhone 5S 환경에서 구동해봤습니다.







    이렇게 설정 후, 왼쪽 상단의 재생 버튼을 클릭하여 빌드를 한 뒤, 실행되어 집니다.







    먼저, 안드로이드 에뮬레이터처럼 구동이 되는데,


    정말 ㅃㅃ빠른 속도로 시뮬레이터가 켜집니다.ㅎㄷㄷ










    그렇게 되고나서, 실행 결과, 아래처럼 뜨는데...


    왜 이렇게 뜨지...


    나는 가운데를 원하는데...







    그래서 다시 프로젝트를 생성해서,


    아래처럼 초기에 아이폰 레이아웃처럼 설정을 했습니다.



    레이아웃 하단을 클릭해서 조절 가능합니다.









    조절 후, 이전과 동일하게 label을 불러와 실행시켜봤습니다.



    흠... 그런데도 약간 찐다같이 정중앙으로 위치하진 않더군요...







    아무튼 안드로이드와 유사하게 UI를 통해서 라벨을 이용해 hello world를 작성할 수 있습니다.


    아이폰 소스코드는 .m 확장자로 시작하구요.




    * ViewController.m


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    //
    //  ViewController.m
    //  hellworld2
    //
    //  Created by MoonYeonSu on 2016. 2. 12..
    //  Copyright © 2016년 MoonYeonSu. All rights reserved.
    //
     
    #import "ViewController.h"
     
    @interface ViewController ()
     
    @end
     
    @implementation ViewController
     
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
     
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
     
    @end
     
    cs





    * AppDelegate.m


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
     
    //
    //  AppDelegate.m
    //  hellworld2
    //
    //  Created by MoonYeonSu on 2016. 2. 12..
    //  Copyright © 2016년 MoonYeonSu. All rights reserved.
    //
     
    #import "AppDelegate.h"
     
    @interface AppDelegate ()
     
    @end
     
    @implementation AppDelegate
     
     
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        return YES;
    }
     
    - (void)applicationWillResignActive:(UIApplication *)application {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }
     
    - (void)applicationDidEnterBackground:(UIApplication *)application {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }
     
    - (void)applicationWillEnterForeground:(UIApplication *)application {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }
     
    - (void)applicationDidBecomeActive:(UIApplication *)application {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }
     
    - (void)applicationWillTerminate:(UIApplication *)application {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
     
    @end
     
    cs





    그리고 각 소스파일에 딸려오는 헤더 파일들이 있습니다.




    이렇게 해서 첫 아이폰 앱 만들기를 해보았습니다!


    흠... 아직까진 미숙하나 점차 확인하여서 세부성을 더해야 할 것 같습니다!






    댓글

Designed by Tistory.