Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UIApplicationShortcutIcon

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

enter image description here

like image 482
Khant Thu Linn Avatar asked Sep 28 '15 06:09

Khant Thu Linn


1 Answers

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.

like image 115
Sahil Kapoor Avatar answered Sep 28 '22 18:09

Sahil Kapoor