Sample code on dynamic UIApplicationShortcutItems

前端 未结 4 912
眼角桃花
眼角桃花 2021-02-04 10:32

I\'m looking after some Obj-C sample code for a dynamic UIApplicationShortCutItem.

Basically, I have three static UIApplicationShortcutItems an

4条回答
  •  花落未央
    2021-02-04 11:21

    You can use the following code to add shortcutitem for you app dynamic:

    UIApplicationShortcutIcon * photoIcon = [UIApplicationShortcutIcon iconWithTemplateImageName: @"selfie-100.png"]; // your customize icon
    UIApplicationShortcutItem * photoItem = [[UIApplicationShortcutItem alloc]initWithType: @"selfie" localizedTitle: @"take selfie" localizedSubtitle: nil icon: photoIcon userInfo: nil];
    UIApplicationShortcutItem * videoItem = [[UIApplicationShortcutItem alloc]initWithType: @"video" localizedTitle: @"take video" localizedSubtitle: nil icon: [UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypeCaptureVideo] userInfo: nil];
    
    [UIApplication sharedApplication].shortcutItems = @[photoItem,videoItem];
    

提交回复
热议问题