Skip to content

XCode:iPhone:Basic

XCode에서 iPhone 앱 개발 기초.

Info

Version 12.4 (12D4e) 에서 버튼 터치 다운 이벤트 추가 방법

프로젝트 생성

iOS > App 선택.

스토리 보드 시작

스토리 보드에 버튼과 같은 컨트롤을 올리고 싶다면, 메뉴에서 View > Show Library 선택 한다. (단축키: Command + Shift + L)

버튼

우선 에디터 우상단에 있는 "Add Editor on Right" 버튼을 클릭하여 코드 창과 스토리보드 창을 나눈다.

버튼 컨트롤에서 오른버튼 클릭, Send Events > Touch Down 를 좌클릭 하고, ViewController.h 의 클래스에 드래그하면 이벤트를 추가할 수 있다.

라벨

라벨을 우클릭 -> 드래그 하거나,

우클릭 팝업 -> Reference Outlets > New Referencing Outlet 를 좌클릭 하고, ViewController.h 의 클래스에 드래그하면 객체 참조를 추가할 수 있다.

최종 코드

ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *label;

- (IBAction)touchDown:(id)sender;

@end

ViewController.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (IBAction)touchDown:(id)sender {
    [self.label setText: @"MyLabel!"];
}

@end

라이브러리 추가

최상위, 프로젝트 파일을 선택, General 탭 선택, Frameworks, Libraries, and Embedded Content 항목에 + 버튼을 클릭하여 목록에서 선택한다.

See also