Custom UIApplicationShortcutIcon
Asked Answered
S

1

6

Is it possible to create custom UIApplicationShortcutIcon? Or only the one given by apple ?

enter image description here

Socratic answered 28/9, 2015 at 6:13 Comment(0)
I
11

Yes it is possible to UIApplicationShortcutIcon. According to docs:

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)

You can use iconWithTemplateImageName: to intialiaze new button. Eg:

- (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;
}

Refer to Apple Docs.

Inessive answered 28/9, 2015 at 7:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.