I am struggling to change the height of my iOS 10 widget in compact mode.
All I have is an empty widget, no views inside it. Still, no matter what I set for the compact height, it seems to ignore it.
Here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeExpanded];
}
- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize{
if (activeDisplayMode == NCWidgetDisplayModeCompact) {
self.preferredContentSize = CGSizeMake(0, 50);
}
else{
self.preferredContentSize = CGSizeMake(0, 200);
}
}
Could this be an issue with beta software? I am on Xcode 8 beta and iOS 10 beta 7.
1) Set the display mode to
NCWidgetDisplayModeExpanded
inviewDidLoad
2) Implement this protocol method
set
prefferedContentSize
inviewDidAppear
or after then. I guess that widget will resize before view appears. The widget's width is NOT SCREEN_WIDTH because of gap between iPhone screen edge.According to the What's new in Cocoa Touch session from WWDC 2016 (around the 44:00 mark):
So, it seems that setting a
preferredContentSize
forNCWidgetDisplayModeCompact
is completely ignored (the fixed size appears to be 110pts).In SWIFT 3:
The following property for your TodayViewController will return max size for compact mode: