Categories
Programming/iOS

[iOS] 用 UIImagePickerController 從 相片庫挑選一張照片來顯示片段碼 , UIImagePickerControllerSourceTypeSavedPhotosAlbum , didFinishPickingMediaWithInfo ,

.h檔: 要加

@interface ViewController : UIViewController

 

.m 檔:

.
.
.

    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    picker.allowsEditing = YES;

    [self presentViewController:picker animated:YES completion:nil];

    
    resultBox.text = @"Hello World!";
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    [self dismissViewControllerAnimated:YES completion:nil];

    NSLog(@"\nin didFinishPickingMediaWithInfo\n");
    imgBox.image = [info objectForKey:UIImagePickerControllerOriginalImage];

}

螢幕快照 2014 03 20 下午6 19 07