How to resize the height of widget in iOS 10?

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

Replies

I'm having the same issue. I hope this is just temporary.

Its always been limited officially. How are you determining your max height?

They are no longer tall enough to display the same data as before.

I think its an error make the widgets height not resizable 😟

Hi,


I have noticed the same. I tested an XCode 7.3.1 iOS 9 SDK compiled app via TestFlight on an iPhone 5 with iOS 10 beta 1. So the app was not compiled using the XCode beta.


Since iOS 8, widget height can be set in the viewController used (where widgetHeight contains the preferred height):

self.preferredContentSize = CGSizeMake(0, widgetHeight);

Of course it could never be set higher than the actual available vertical space on screen.


This no longer works in iOS 10 beta 1, and is documented as a known issue in the release notes http://adcdownload.apple.com/WWDC_2016/iOS_10_beta/iOS_10_beta_Release_Notes.pdf


Last page: "Legacy widgets may be cut off".


So I do expect this is just beta 1 stuff...


Either this will be fixed, or setting the widget height will be an iOS 10 SDK only thing, leaving iOS 9 SDK compiled widgets the default height. I expect the first.


Also, I noticed that the iOS 10 beta built-in widgets such as Siri app suggestions and Weather have a "Show more" / "Show less" button on the right side in the widget header, which acts as an expand / collapse feature. This is new, I did see "Show more" buttons in iOS 8/9 widgets, but never in the actual widget header.


Also, the Weather widget expanded (city + temp with a row of hourly forecasts) is higher than the Siri app suggestions expanded (2 rows of app icons), which suggest there is such a thing as specifying the height of a widget in "expanded mode". Seen on iPhone 5 with iOS 10.


Let's hope that the collapsed version of a widget can also be set in height, not just the expanded version. Or, that we can expand widgets by default. Some widgets just do need a higher size than this default.


Looking forward to the beta SDK documentation and beta 2...


Jeroen

I think the best way to sove this porblem right now is to add more widgets in one app, just like Launcher.

- (CGSize)widgetMaximumSizeForDisplayMode:(NCWidgetDisplayMode)displayMode NS_AVAILABLE_IOS(10_0);

I found this new API, [self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeExpanded];😁

Nice! Does it have any methods relating to setting height to a certain amount of pixels?


I can't get my widgets apps to compile and see how it looks, due to another issue (https://forums.developer.apple.com/thread/49116)


But I did find this one after inspecting the extensionContext method you posted.


CGSize maxExpandedSize = [self.extensionContext widgetMaximumSizeForDisplayMode:NCWidgetDisplayModeExpanded];
CGSize maxCompactSize = [self.extensionContext widgetMaximumSizeForDisplayMode:NCWidgetDisplayModeCompact];


This returns the max possible size.


Now, the question is, how do we set it.

Yes, implement this new protocal method:

- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize{

if (activeDisplayMode == NCWidgetDisplayModeCompact) {

self.preferredContentSize = maxSize;

}

else

self.preferredContentSize = CGSizeMake(0, 200);

}

and it acts just like the official widget app😁

Haha,Thank you so much.


By the way, what kind of app are you making now?

The default height is limited. But users can switch between two NCWidgetDisplayModes.


public enum NCWidgetDisplayMode : Int { 
  case compact //default
  case expanded
}


They mentioned it in the session 205 "What's new in Cocoa Touch"

I tried implementing the delegate methods for

widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize)
and
widgetMaximumSize(for displayMode: NCWidgetDisplayMode)
. Despite the console printing the correct
displayMode
,
maxSize
, and
preferredContentSize
, the widget remains at the default height. Any chance you can share a simple, but complete code example for getting the height to update to the
preferredContentSize
? As an aside, I'm looking for a
preferredContentSize
of 250.

Hello,


You should set the display mode to NCWidgetDisplayModeExpanded first in viewDidLoad.Here is the code:


[self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeExpanded];


Hope this can help you🙂