How to resize the height of widget in iOS 10?

It seems that the height of widget is limited in iOS 10.

Replies

Ah, that's what I was missing, thanks! 🙂


Any idea if it's possible to only show an expanded state and not both a compact/expanded one? Seems like that isn't supported, but I might be missing something here too.

I think it is impossible to only show an expanded state. Because the old way to set preferredContentSize is not working anymore.

The sizechange works fine, but ...


On my device the position of the "topLayoutGuide" changes after the first tap on the "Widget Size Change"-Button from starting value "0" to "34". Because of autolayout (my Views are attached to the topLayoutGuide) all Subviews move to the wrong position (34 points to low).


Is this a bug or what is wrong with my widget? Here is my code:


func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
     
        self.preferredContentSize = (activeDisplayMode == .compact) ? maxSize : CGSize(width: maxSize.width, height: 200)
}

This is an issue I've encountered, but only when running in Simulator. I'm curious to know if you're seeing this bug on an actual device too. I assume this is what you meant by "On my device" though. What device are you using?

On a real device - I am testing the widget extension on an iphone 6s.


EDIT: It's very strange. When my widget is at the second position (under weather) everything works fine on my device...

Oh, interesting. I'm seeing this on my iPhone 5s now too 😟. I had my widget positioned at the very bottom (just above the the "Edit" button). Moving it to the top triggered this bug. It does appear to be position dependent somehow.


Update: I'm able to get around this issue by removing the vertical spacing to top layout guide constraint and using a center vertically in container constraint instead. Of course this won't be a viable solution for everyone.

I'm seeing this issue in the Simulator as well. Has anyone found a workaround to this?


Edit: I was able to fix this by setting the constraint to the top of the view instead of the top layout guide.

Thanks for the info. It seems that the _minimum_ height of the widget is 110 (which is the maxSize for compact...)?


Anyone was able to display a smaller widget?

110 is definitely the minimum height and is the size in compact display mode.


The maximum height depends on what device you are on and even whether you have swiped down (to see the notifications screen) and then left to see the widgets, or whether you've just swiped left to see the widgets from the home screen. Those last two cases have slightly different chrome around the main part of the view. They both have a search bar at the top, but only the view that came from notification center has a page indicator at the bottom (since that's the only one with pages).


In the notification center->widget case they decided to limit the max height so that an entire widget (including its title) could be seen. In beta 6 you can also see the title bar of the next widget (I can't remember, but I think beta 5 didn't show the next title bar). That looks nice and I think is the right choice.


In the swipe-to-see-widget case (either from the lock screen or home screen), the widget seems to fill the height of the screen so it underlaps the search bar. The search bar is taller than the widget's title bar so a widget that tries to be as big as it can will result in a size that can't all be seen at once. That does not look nice!


I really wish we could post screenshots to this forum as the iOS 10 enhancements to my 'Adaptivity' app shows this really well.

Thanks for your detailed reply!


I think the 110 minimum height is a bad choice. What if your widget only displays a single line?


Or, in my case, the ideal height is 120. So now I can either squeeze it down to 110 and only go with compact mode, or use the expanded mode, which will allow the user to switch between 110 and 120 height, which does not make any sense.


PS: If you have the time, you could put the screenshots elsewhere and post a link?

If you search for my username on imgur you should find a few images. Hope they help.

got it, txs!

On a side note, widget minimum size changes depending on the user's text size in System Settings. 😕

on startup of the widget I am often getting a smaller size than 110, which is messing up my layouts. After toggling the Show More/Less button the sizes are correct. But assuming a user will see the initial state most often, this is a big pain for me. Spent a lot of time xib twiddling to make all font sizes work right.

Plus, on inital load the view size can be from 4.5 to 8 pts size difference (or more).