'네비게이션과 이미지버튼 만들기'에 해당되는 글 1건

  1. 2013.06.16 MainViewController.m 네비게이션과 이미지버튼 만들기
2013.06.16 21:14

MainViewController.m 네비게이션과 이미지버튼 만들기



//

//  MainViewController.m

//  ImageTest

//

//  Created by Macintosh on 13. 5. 3..

//  Copyright (c) 2013 hj. All rights reserved.

//


#import "MainViewController.h"


@interface MainViewController ()


@end


@implementation MainViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    

    [super viewDidLoad];

// Do any additional setup after loading the view.

    

    [self.navigationItem setTitle:@"Main View"];

    

    imgView = [[UIImageView alloc] init];

    [imgView setFrame:CGRectMake(35, 50, 249, 165)];

    [imgView setImage:[UIImage imageNamed:@"img01.png"]];

    [self.view addSubview:imgView];

    [imgView release];

    

//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

//    [btn setFrame:CGRectMake(40, 350, 80, 40)];

//    [btn setTitle:@"Show" forState:UIControlStateNormal];

//    [btn addTarget:self action:@selector(showImage) forControlEvents:UIControlEventTouchUpInside];

//    [self.view addSubview:btn];

//    

//    btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

//    [btn setFrame:CGRectMake(200, 350, 80, 40)];

//    [btn setTitle:@"Hide" forState:UIControlStateNormal];

//    [btn addTarget:self action:@selector(hideImage) forControlEvents:UIControlEventTouchUpInside];

//    [self.view addSubview:btn];

    

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    [btn setTag:1];

    [btn setFrame:CGRectMake(20, 350, 80, 53)];

    [btn setImage:[UIImage imageNamed:@"i01.png"] forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

    

    btn = [UIButton buttonWithType:UIButtonTypeCustom];

    [btn setTag:2];

    [btn setFrame:CGRectMake(120, 350, 80, 53)];

    [btn setImage:[UIImage imageNamed:@"i02.png"] forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

    

    btn = [UIButton buttonWithType:UIButtonTypeCustom];

    [btn setTag:3];

    [btn setFrame:CGRectMake(220, 350, 80, 53)];

    [btn setImage:[UIImage imageNamed:@"i03.png"] forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

    

}


- (void) changeImage:(UIButton *) sender {

 NSString *imgName = [NSString stringWithFormat:@"img0%d.png", [sender tag]];

    [imgView setImage:[UIImage imageNamed:imgName]];

    

    

//    switch ([sender tag]) {

//            case 1:[imgView setImage:[UIImage imageNamed:@"img01.png"]];

//            

//

//            break;

//        case 2:[imgView setImage:[UIImage imageNamed:@"img02.png"]];

//            break;

//        case 3:[imgView setImage:[UIImage imageNamed:@"img03.png"]];

//            

//            break;

//    default:

//            break;

//    

//    }


}


- (void) showImage {

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:2.f];

    [imgView setAlpha:1.f];

    [UIView commitAnimations];

}

- (void) hideImage {

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.f];

    [imgView setAlpha:0.f];

    [UIView commitAnimations];


    

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


Trackback 0 Comment 0