问题
How to add custom images as UIApplicationShortcutIcon
for UIApplicationShortcutItem
? which is similar like photos UIApplicationShortcutItem
in Photos/Message app for most recent.Because all icon are Created an icon from a custom image.The provided image named will be loaded from the app's bundle and will be masked to conform to the system-defined icon style.So how can i get color image as UIApplicationShortcutIcon
programmatically?
回答1:
You can add short cut icons from app delegate also.Here img_editProduct and img_Classifieds are custom images added in .xcassests file
- (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:
Don't use an emoji in place of a template icon. Emojis don't align properly when the text is right-aligned. Also, emojis are full color, whereas template icons should be monochromatic. You can choose from among the many system-provided template icons or you can create a custom template icon. For detailed guidance on icon sizes, padding, and positioning, download Home Screen Quick Action Icon Template from https://developer.apple.com/design/downloads/Quick-Action-Guides.zip. To learn more about designing a template icon, see Template Icons.
As per above text, I dont think there is no way to display coloured icon. May be we will get in future update.
来源:https://stackoverflow.com/questions/36130654/how-to-add-custom-images-as-uiapplicationshortcuticon-for-uiapplicationshortcuti