2
votes

I'm building a widget for an app in iOS with WidgetKit, SwiftUI etc. I've created a custom intent and custom object to use in the app and when tapping on "Edit Widget" I take a custom list of items from UserDefaults.

The question is, can I customize the appearance of the second view that iOS shows me with the list of items etc?

This is the view I'm talking about:

enter image description here

Looking around I found this: https://developer.apple.com/videos/play/wwdc2020/10194 that gives me a lot of good hints but nothing on what i'm trying to achieve.

In the video they show this:

enter image description here

That seams to be the same view but with some customization.

My end goal is to remove the search bar. Thank you very much!

1

1 Answers

2
votes

When you create items for the INObjectCollection for your Intent you can set:

  • identifier
  • display
  • pronunciationHint
  • subtitle
  • image

Here is an example how to add subtitle and image to the INObjectCollection item:

class IntentHandler: INExtension, TestIntentHandling {
    func provideItemsOptionsCollection(for intent: TestIntent, with completion: @escaping (INObjectCollection<Item>?, Error?) -> Void) {
        let items: [Item] = [
            .init(
                identifier: "1",
                display: "SoupPay Credit",
                subtitle: "$248.20",
                image: nil
            ),
            .init(
                identifier: "2",
                display: "SoupPay Titanium Credit",
                subtitle: "$602.01",
                image: nil
            ),
            .init(
                identifier: "3",
                display: "Apple Card",
                subtitle: "$17.28",
                image: nil
            ),
            .init(
                identifier: "4",
                display: "Other Card",
                subtitle: "$123.32",
                image: INImage(url: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Stack_Overflow_icon.svg/200px-Stack_Overflow_icon.svg.png")!)!
            ),
        ]
        completion(INObjectCollection(items: items), nil)
    }
}

enter image description here