[英]xcode, How do I add an image view that changes images depending on what I select in camera roll?
There is no view controller or any interfacebuilder, I want to build this with just code. 没有视图控制器或任何interfacebuilder,我只想用代码来构建它。 I have the method setup where you can click on button to go to camera roll, but now I am lost on what to do next.
我有方法设置,可以单击按钮转到相机胶卷,但是现在我迷失了下一步。 I need a way to select an image and it will allow me to add the image to an image view.
我需要一种选择图像的方法,它将允许我将图像添加到图像视图中。 Any tips on what to do will be appreciated.
任何建议做什么都将不胜感激。
- (void)viewDidLoad {
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
[self.view addSubview: imgView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
}
-(void)aMethod{
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsImageEditing = YES;
[[self navigationController] presentModalViewController:picker animated:YES];
}
I think this could help :- 我认为这可以帮助:-
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
as delegete of imagePickerController
作为imagePickerController的
imagePickerController
You can get the image by info key :- 您可以通过信息键获取图像:-
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
For more see this link . 有关更多信息,请参见此链接 。
info is a dictionary
containing the original image and the edited image , If an image was picked; info是包含原始图像和已编辑图像的
dictionary
,如果已选择图像; or a filesystem URL for the movie, if a movie was picked. 或电影的文件系统URL (如果已选择电影)。 The
dictionary
also contains any relevant editing information. 该
dictionary
还包含任何相关的编辑信息。 The keys for this dictionary
are listed in Editing Information Keys . 该
dictionary
的键在“ 编辑信息键”中列出。
The previous answer was correct....but here is another way of looking at it.... 先前的答案是正确的...。但这是查看它的另一种方式...。
As long as you have your code calling your photo album the next step you will need is: 只要您有调用相册的代码,下一步您将需要:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
That will place the returned info into your selected imageView..... 这会将返回的信息放入您选择的imageView中。
What you have in your posted code is opening your photo library....the net step is to say OK....Ive finished picking my media....what am I going to do with it? 您发布的代码中的内容正在打开您的照片库。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.