这就是我们在WidgetKit
中通过使用Intent定义文件提供“编辑小部件”功能的方式。
意图定义文件
编辑小部件期间的结果
为了提供一个选择列表,在Intent处理过程中(点击编辑小部件页面时),这是我们的代码。
import Intents
class IntentHandler: INExtension, ConfigurationIntentHandling {
func provideWidgetItemOptionsCollection(for intent: ConfigurationIntent, with completion: @escaping (INObjectCollection<WidgetItem>?, Error?) -> Swift.Void) {
var widgetItems = [WidgetItem]()
widgetItems.append(WidgetItem(identifier: "1", display: "Visit grandma"))
widgetItems.append(WidgetItem(identifier: "2", display: "Don't forget milk"))
widgetItems.append(WidgetItem(identifier: "3", display: "Buy socks"))
widgetItems.append(WidgetItem(identifier: "4", display: "Pick up laundry"))
widgetItems.append(WidgetItem(identifier: "5", display: "Reply email"))
widgetItems.append(WidgetItem(identifier: "6", display: "Meeting at 3pm"))
let collection = INObjectCollection(items: widgetItems)
completion(collection, nil)
}
override func handler(for intent: INIntent) -> Any {
// This is the default implementation. If you want different objects to handle different intents,
// you can override this and return the handler you want for that particular intent.
return self
}
}
这就是
意向处理期间的结果
我想知道,有没有办法在UI上创建多个部分?
例如,
[Personal]
"Visit grandma"
"Don't forget milk"
"Buy socks"
"Pick up laundry"
[Work]
"Reply email"
"Meeting at 3pm"
- 谢谢-谢谢
1条答案
按热度按时间kupeojn61#
这就是解决办法。
,结果如下。