Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 218
Noha Mohamed Avatar asked Jan 28 '26 13:01

Noha Mohamed


1 Answers

Solution

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...

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
}
like image 171
mgyky Avatar answered Jan 30 '26 07:01

mgyky