Swift: INImage does not respect specified width and height

Viewed 125

I am implementing iOS14 widgets with configuration intent that allows users to select a Tweet when the users tap "Edit Widget".

Implementation works well but the image is not sized to the specified width and height in the selection pop up, and seems to be capped at the row height.

Code:

class IntentHandler: INExtension, SelectTweetIntentHandling {
    
    func provideTweetOptionsCollection(for intent: SelectTweetIntent, with completion: @escaping (INObjectCollection<TweetParam>?, Error?) -> Void) {
        
        let tweetParams = [
            TweetParam(identifier: "1", display: "Title 1", subtitle: "Subtitle 1", image: INImage(url: URL(string: "https://i.pinimg.com/474x/69/77/b7/6977b70a129ec184527433bbdf9fe457.jpg")!, width: 200, height: 200)),
            TweetParam(identifier: "2", display: "Title 2", subtitle: "Subtitle 2", image: INImage(url: URL(string: "https://i.pinimg.com/474x/69/77/b7/6977b70a129ec184527433bbdf9fe457.jpg")!, width: 200, height: 200)),
            TweetParam(identifier: "3", display: "Title 3", subtitle: "Subtitle 3", image: INImage(url: URL(string: "https://i.pinimg.com/474x/69/77/b7/6977b70a129ec184527433bbdf9fe457.jpg")!, width: 200, height: 200))
        ]
        let collection = INObjectCollection(items: tweetParams)
        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
    }
    
}

Outcome: enter image description here

Noticed that I had specified size 200x200 as an exaggeration, but the image size does not respect that. How do I manually size the image to my specified size.

1 Answers

It looks like you are invoking the shortcut from the Shortcuts app. I noticed the same thing running the shortcut I am working on from the app. However, I do see it respecting the height and width when invoking via voice.

It looks like there is a set height and width for images in this view, and the provided height and width are ignored in this case.

What you can try is using the imageSize(for:) method which should respond with "The image size preferred by the response object"

Andy

Related