How to add custom images like UIApplicationShortcutIcon for UIApplicationShortcutItem?

How to add custom images like UIApplicationShortcutIcon for UIApplicationShortcutItem ? which is similar to UIApplicationShortcutItem photos in the Photos / Post app for the very latest. Because all the icons are created by the icon from the user image. The image will be downloaded from the application package and will be masked in accordance with the system-defined icon style. So how can I get a color image like UIApplicationShortcutIcon programmatically?

+2
source share
2 answers

You can also add shortcut icons from the application delegate. Here img_editProduct and img_Classifieds added custom images. xcassests .

 - (void)shortcutsWithIcon { @try { UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"img_editProduct"]; UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"img_Classifieds"]; UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.3dtouchApp.postAnItem" localizedTitle:@"Post an Item" localizedSubtitle:@"Add new product for sale" icon:icon1 userInfo:nil]; UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.3dtouchApp.LatestAds" localizedTitle:@"Latest Ads" localizedSubtitle:@"View top recent Ads" icon:icon2 userInfo:nil]; NSArray *items = @[item2, item1]; [UIApplication sharedApplication].shortcutItems = items; } @catch (NSException *exception) { } } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if (self.window.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) { [self shortcutsWithIcon]; if ([item.type isEqualToString:@"com.3dtouchApp.postAnItem"]) { ***//Code for launch your screen*** } if ([item.type isEqualToString:@"com.3dtouchApp.LatestAds"]) { ***//code for launch your screen*** } } return YES; } 
+2
source

Do not use emoji instead of a template icon. Emojis do not align correctly when the text is right-aligned. In addition, emojis are full-color, while template icons should be monochromatic. You can choose among many system template icons, or you can create a custom template icon. A detailed guide on icon sizes, indentation, and positioning, download the Icon Template https://developer.apple.com/design/downloads/Quick-Action-Guides.zip . For more information on creating a template icon, see "Template Icons".

According to the text above, I don't think there is no way to display a colored icon. Perhaps we will be updated in the future.

0
source

Source: https://habr.com/ru/post/1265911/


All Articles