Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a custom icon for a static UIApplicationShortcutItem in my iOS 9 App?

I'm currently implementing home screen Quick Actions for my iOS 9 app using 3D Touch. I have several actions using the existing System icons from the defined UIApplicationShortcutIconType enum.

An Example:

<dict>     <key>UIApplicationShortcutItemIconType</key>     <string>UIApplicationShortcutIconTypeSearch</string>     <key>UIApplicationShortcutItemTitle</key>     <string>Search for Parking</string>     <key>UIApplicationShortcutItemType</key>     <string>SEARCH</string> </dict> 

However, for one of the actions I want to use a custom icon. I have tried replacing the UIApplicationShortcutItemIconType string with the name of my image asset, but that doesn't work.

It's easy enough to do for dynamic actions using UIApplicationShortcutIcon.iconWithTemplateImageName(), but this action needs to be static.

like image 521
Chris Allwein Avatar asked Sep 13 '15 20:09

Chris Allwein


People also ask

What are quick actions iOS?

Quick actions are a great way to provide your users fast access to your app's common functionality within the home screen. iOS 13 introduced the concept of quick actions, where a user can touch and hold an app icon to display a set of shortcuts or actions to perform right from the home screen.


1 Answers

Instead of using the UIApplicationShortcutItemIconType key, replace it with the UIApplicationShortcutItemIconFile key and then supply the name of your image file or ImageAsset.

Like this:

<dict>     <key>UIApplicationShortcutItemIconFile</key>     <string>MyCustomImageName</string> </dict> 

The rest of the keys can stay as they were.

like image 92
Chris Allwein Avatar answered Sep 28 '22 18:09

Chris Allwein