Today Widget Extension Height - iOS10 Today Widget Extension Height - iOS10 ios ios

Today Widget Extension Height - iOS10


The height of the widget in iOS 10 is exactly 110 in compact mode. It can be set to whatever height you want in expanded mode, but in compact mode it will always be 110 and that can't be overwritten.


Solution is setting the preferredContentSize at viewDidLoad method.

Here is the example:

Swift 3 and later

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    }} @available(iOS 10.0, *)    @available(iOSApplicationExtension 10.0, *)    func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {        if activeDisplayMode == .expanded {            self.preferredContentSize = CGSize(width: self.view.frame.size.width, height: CGFloat(3)*self.tableView.rowHeight)        }else if activeDisplayMode == .compact{            self.preferredContentSize = CGSize(width: maxSize.width, height: 110)        }    }

Warning

You should use your specific height for your case. 110 is valid in my scenario.

Hope this will fix your issue.

Best


To get the max height of the widgets active display mode, do this in your UIViewController

let context = self.extensionContextif let context = context{    let height = context.widgetMaximumSize(for: context.widgetActiveDisplayMode).height}

To get the max height of expanded and compact individually regardless of the current display mode, do this:

var context = self.extensionContextif let context = context{    let compactHeight = context.widgetMaximumSize(for: .compact).height    let expandedHeight = context.widgetMaximumSize(for: .expanded).height}