본문 바로가기

C/Objective C/ios

아이폰 ImageVIew 만들기 예제 따라하기

- 아이폰 ImageView를 이용해서 이미지를 아이폰 화면에 띄어 보자.


- 화면 디자인


- IamgeView 만들기 순서

1. Xcode 실행
2. Single View Application
3. Project Name : “UIImageViewTest01”
4. 이미지 파일 생성 후(파일 이름은 “ficc.jpg“) Xcode로 드래그
5. storyboard에 Button과 UIImageView 위치
6. Assistant Editor로 Button과 ImageView 드래그
7. “myButton”과 “myImageView” 입력
8. Button을 Assistant Editor로 드래그 Connection을 Action으로 변경 “tapBtn” 입력

 9. Control 키를 누를 상태에서 Assistant Editor에 있는 -(IBAction)tapBtn; 에 드래그 

10. ViewController.m 파일에 입력

-(IBAction)tapBtn{
myImageView.image = {UIimage imageNamed:“@”test.jpg“

}

11. Command+R


- ViewController.m 소스파일

#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController

@synthesize myButton;

@synthesize myImageView;


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}


- (void)viewDidUnload

{

    [self setMyButton:nil];

    [self setMyImageView:nil];

    [super viewDidUnload];

    // Release any retained subviews of the main view.

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

} else {

    return YES;

}

}


- (IBAction)tapBtn:(id)sender {

myImageView.image = [UIImage imageNamed:@"ficc.jpg"];

}

@end


- 실행화면