iosobjective-c3dtouchuiapplicationshortcutitem

Can we change 3D touch short cut item icon?


Here is my code.

    UIApplicationShortcutItem *bookmarksShortcutItem = [[UIApplicationShortcutItem alloc] initWithType:@"bookmarks" localizedTitle:@"Bookmarks" localizedSubtitle:@"test" icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeBookmark] userInfo:@{@"type":@"bookmarks"}];

So can I add my custom icon instead of UIApplicationShortcutIconTypeBookmark?

Thanks in advance.


Solution

  • This is how you do it:

    UIApplicationShortcutIcon *shortcutIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"IMAGE_NAME"];
    UIMutableApplicationShortcutItem *option = [[UIMutableApplicationShortcutItem alloc] initWithType:@"uniqueIdentifier"
                                                                                       localizedTitle:@"title"
                                                                                    localizedSubtitle:nil
                                                                                                 icon:shortcutIcon
                                                                                             userInfo:nil];
    [UIApplication sharedApplication].shortcutItems = @[option];