ios相册选取图片代码

//
// MyController.m
// D
//
// Created by apple on 12-4-17.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "MyController.h"
#define MNSLog(info) NSLog(info)

@implementation MyController

-(IBAction) myMethod:(id)sender{
UIImagePickerController *pc = [[UIImagePickerController alloc]init];
pc.delegate = self;
pc.allowsEditing = NO;
//pc.allowsImageEditing = NO;
pc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pc animated:YES];
[pc release];
}
//3.x
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

MNSLog(@"3.x");
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImageView *iview = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:iview];

[self dismissModalViewControllerAnimated:YES];

}
//2.x
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
MNSLog(@"2.x");
}
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
MNSLog(@"cancle");

}

// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"click" style:UIBarButtonItemStylePlain
target:self action:@selector(myMethod:)];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
}


@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值