I need to create a Mac application using Objective-C. The application has to use PHPickerViewController to provide user a familiar interface to pick photos.
Here is the Objective-C code that used to present the photo picker.
//ViewController.h
#import <Cocoa/Cocoa.h>
#import <PhotosUI/PhotosUI.h>
@interface ViewController : NSViewController<PHPickerViewControllerDelegate>
@property (nonatomic, weak) IBOutlet NSImageView *myImageView;
@end
// ViewController.m
@implementation ViewController
PHPickerViewController* pickerViewController = nil;
- (void)pickPhotos {
PHPickerConfiguration *config = [[PHPickerConfiguration alloc] init];
config.selectionLimit = 0; // Allow multiple selections
config.filter = [PHPickerFilter imagesFilter]; // Filter for images
pickerViewController = [[PHPickerViewController alloc] initWithConfiguration:config];
pickerViewController.preferredContentSize = NSMakeSize(800, 600);
pickerViewController.delegate = self; // Set the delegate to handle selection
[self presentViewControllerAsModalWindow:pickerViewController];
- (IBAction)clicked:(id)sender {
NSLog(@"Button Clicked");
[self pickPhotos];
}
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results {
if (pickerViewController) {
[picker dismissViewController:pickerViewController];
}
}
@end
Can you please guide me to show the photo picker to a bigger size?
Hey @brightdl,
Thanks for submitting that Feedback!
Just adding in here that you should also be able to set the PHPickerViewController's view's frame, for example:
pickerViewController.view.frame = NSRect(origin: .zero, size: .init(width: 800, height: 600))
Technically, this is only documented as being supported when the picker controller is added as a child of another view controller, but in practice I think it should work here without doing the view controller containment dance. (If you'd like to be safe though, you can definitely do this with some simple view controller containment.)
--Greg