自定义 UIApplicationShortcutIcon

Custom UIApplicationShortcutIcon

是否可以创建自定义 UIApplicationShortcutIcon?还是只有苹果给的那个?

是的,可以使用 UIApplicationShortcutIcon。根据文档:

There are three types of quick action icon:

  1. An icon from a system-provided library of common types, as described in the UIApplicationShortcutIconType enumeration

  2. An icon derived from a custom template image in your app’s bundle and preferably in an asset catalog

  3. An icon representing a contact in the user's address book, which you access through the ContactsUI framework (see ContactsUI Framework Reference)

您可以使用iconWithTemplateImageName: 初始化新按钮。例如:

- (void)createDynamicShortcutItems {

    // create several (dynamic) shortcut items
    UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc]initWithType:@"Item 1" localizedTitle:@"Item 1"];
    UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItem alloc]initWithType:@"Item 2" localizedTitle:@"Item 2"];
    UIApplicationShortcutItem *item3 = [[UIApplicationShortcutItem alloc]initWithType:@"Item 3" localizedTitle:@"Item 3"];

    // add all items to an array
    NSArray *items = @[item1, item2, item3];

    // add the array to our app
    [UIApplication sharedApplication].shortcutItems = items;
}

参考Apple Docs.