Implementation Details of a macOS Icon & Launch Image Generator for iOS
This article explains how a simple macOS application was built to generate iOS app icons and launch images of various sizes, describing its UI layout, resource‑plist configuration, and the Objective‑C code that handles path selection, image processing, and export logic.
The article introduces a macOS utility named "mac app—图标&启动图生成器" created to automate the production of iOS app icons and launch images, eliminating repetitive manual slicing of assets.
The UI consists of a single storyboard‑based window with five controls: an NSImageView for the source image, an NSComboBox for platform selection, a path NSButton, a path NSTextField, and an export NSButton. Layout constraints are defined in Interface Builder.
Platform‑specific size rules are stored in a resource file QiConfiguration.plist. Each platform maps to a dictionary of key / value pairs where the value is an array of items; each item describes the target image’s purpose, name, and size.
The main ViewController loads the previously selected platform and export path from NSUserDefaults in viewDidLoad. The pathButtonClicked: method presents an NSOpenPanel to let the user choose an export directory and writes the chosen path back to the text field.
- (IBAction)pathButtonClicked:(NSButton *)sender {
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
openPanel.canChooseDirectories = YES;
openPanel.canChooseFiles = NO;
openPanel.title = @"选择导出目录";
[openPanel beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse result) {
if (result == NSModalResponseOK) {
self.pathField.stringValue = openPanel.URL.path;
}
}];
}The exportButtonClicked: method validates that an image, platform, and export path are present, saves the selections to NSUserDefaults, and calls generateImagesForPlatform:fromOriginalImage: to create the assets.
- (IBAction)exportButtonClicked:(NSButton *)sender {
NSImage *image = _imageView.image;
NSString *platform = _platformBox.selectedCell.title;
NSString *exportPath = _pathField.stringValue;
if (!image || !platform || !exportPath) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = @"请先选择源图片、平台和导出路径";
alert.alertStyle = NSAlertStyleWarning;
[alert addButtonWithTitle:@"确认"];
[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) {}];
} else {
[[NSUserDefaults standardUserDefaults] setObject:platform forKey:selectedPlatformKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSUserDefaults standardUserDefaults] setObject:exportPath forKey:exportedPathKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[self generateImagesForPlatform:platform fromOriginalImage:image];
}
}The generation routine reads the appropriate configuration array from the plist, creates a platform‑specific output directory, and dispatches to either generateAppIconsWithConfigurations: or generateLaunchImagesWithConfigurations: based on the platform name.
- (void)generateImagesForPlatform:(NSString *)platform fromOriginalImage:(NSImage *)originalImage {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"QiConfiguration" ofType:@"plist"];
NSDictionary *configuration = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSArray<NSDictionary *> *items = configuration[platform];
NSString *directoryPath = [[_pathField.stringValue stringByAppendingPathComponent:platform] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[NSFileManager defaultManager] createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:nil];
if ([platform containsString:@"AppIcons"]) {
[self generateAppIconsWithConfigurations:items fromOriginalImage:originalImage toDirectoryPath:directoryPath];
} else if ([platform containsString:@"LaunchImages"]) {
[self generateLaunchImagesWithConfigurations:items fromOriginalImage:originalImage toDirectoryPath:directoryPath];
}
}Helper methods resize the source image to each required size, export the resulting NSImage as PNG files, and finally open the output folder in Finder.
The full source code is available on GitHub at https://github.com/QiShare/QiAppIconGenerator .
360 Tech Engineering
Official tech channel of 360, building the most professional technology aggregation platform for the brand.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
