Objective-C 기본 문법 복습 - 3

준우·2024년 7월 24일

Objective-C 이야기

목록 보기
15/19
post-thumbnail

Uesr Interface

UIButton

  • IBOutlet
// 헤더파일
// Outlet 선언
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;

@property (weak, nonatomic) IBOutlet UIButton *myButton;

// Action 선언
- (IBAction)tapAction:(id)sender;
  • IBAction
// m 파일
/// IBAction 사용
- (IBAction)tapAction:(id)sender {
		_resultLabel.text = @"여기에 결과가 표시됨.";
}

/// AddTarget 사용
[_myButton addTarget:self
					 action:@selector(changeLabel)
					 forControlEvents:UIControlEventTouchUpInside];

-(void)changeLabel {
		_resultLabel.text = @"짜잔 바꼈습니다~";		
}

Segment Control

  • IBOutlet
@property (weak, nonatomic) IBOutlet UISegmentedControl *mySegCtrl;

- (IBAction)tagOnSeg:(id)sender;
  • IBAction
- (IBAction)tagOnSeg:(id)sender {
		NSLog(@"Segment was tapped");
}

ImageView

  • IBOutlet
// h.file
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
  • ImageView 이미지 띄우기
_myIMageView.image = [UIImage imageNamed: @"cat.jpg"];

Text Field

  • IBOutlet
// h.file
@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;

UI Switch

  • IBOutlet
// h.file
@property (weak, nonatomic) IBOutlet UISwitch *mySwitch;

// Switch 설정
[_mySwitch setOn:false animated:true];

UI Stepper

  • IBOutlet
// h.file
@property (weak, nonatomic) IBOutlet UIStepper *myStepper;

- (IBAction)stepItAction:(id)sender;
  • IBAction
// m.file
- (IBAction)stepItAction:(id)sender {
		_resultLabel.text = [NSString stringWithFormat: @"%f", _myStepper.value];
}

0개의 댓글