Preet Preet - 3 months ago 127
Swift Question

Today widget in iOS10 height issue in swift

I am trying to set the height for the today widget in iOS10 but it doesn't worked. It was working before in iOS9.

Answer

1) Set the display mode to NCWidgetDisplayModeExpanded in viewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()
    self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
}

2) implement given protocal method

[![func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize){
    if (activeDisplayMode == NCWidgetDisplayMode.compact) {
        self.preferredContentSize = maxSize;
    }
    else {
        self.preferredContentSize = CGSize(width: 0, height: 200);
    }
}

enter image description here