How do I change the height of an iOS 10 extension in compact mode? Or more broadly, how do I change the height of an extension without using widgetActiveDisplayModeDidChange
?
Here is the solution to your problem:
override func viewDidLoad() {
super.viewDidLoad()
self.preferredContentSize = CGSize(width:self.view.frame.size.width, height:210)
if #available(iOSApplicationExtension 10.0, *) {
self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded
}
}
the height as 210 how I prefer, you can use any height of course...
If you want to use a fixed size you can use NCWidgetDisplayMode's second option "compact":
@available(iOS 10.0, *)
public enum NCWidgetDisplayMode : Int {
case compact // Fixed height
case expanded // Variable height
}
you can update your code like below :
if #available(iOSApplicationExtension 10.0, *) {
self.extensionContext?.widgetLargestAvailableDisplayMode = .compact
}