Noha Mohamed Noha Mohamed - 1 month ago 10
Objective-C Question

How do I change the height of an iOS extension?

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
?

Answer

I'm using like this, maybe this will help 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
        }
    }

height as 210 how I prefer, you can use any height of course...

UPDATE :

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
}
Comments