如何将自定义图像添加为 UIApplicationShortcutItem
的 UIApplicationShortcutIcon
?这类似于照片应用程序中的最近照片 UIApplicationShortcutItem
。因为所有图标都是从自定义图像创建的。提供的图像名称将从应用程序捆绑包中加载,并且将被掩蔽以符合系统定义的图标样式。那么我如何在编程中获取彩色图像作为 UIApplicationShortcutIcon
?
- (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;
}