本文介绍了动态UIApplicationShortcutItems上的示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为动态UIApplicationShortCutItem
维护一些Obj-C示例代码.
I'm looking after some Obj-C sample code for a dynamic UIApplicationShortCutItem
.
基本上,我有三个静态的UIApplicationShortcutItems
,我只想在特定条件下显示它们.我认为您无法更改静态UIApplicationShortcutItem
的可见状态,因此我正在寻找一种简单的方法来添加动态UIApplicationShortcutItem
.
Basically, I have three static UIApplicationShortcutItems
and I only want to display them under certain conditions. I presume that you can't change the visible status of a static UIApplicationShortcutItem
, so I'm looking after a simple way to add dynamic UIApplicationShortcutItem
s.
推荐答案
您可以使用以下代码为您的应用动态添加快捷方式项:
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];
这篇关于动态UIApplicationShortcutItems上的示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!