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
?
Asked
Active
Viewed 375 times
3

Matthew Frederick
- 22,245
- 10
- 71
- 97

Noha Mohamed
- 147
- 1
- 8
-
Rewording for clarity and ease of reading. – Matthew Frederick Oct 29 '16 at 18:52
1 Answers
2
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
}

MGY
- 7,245
- 5
- 41
- 74
-
this works but i want to change height of widget without using showmore/showless – Noha Mohamed Oct 26 '16 at 13:28
-
-
it works successfully , thanks . Can i hide showmore button and change height ? – Noha Mohamed Oct 27 '16 at 08:33
-
1you can use widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize for change height because compact will make a default (very small) size for your extension. – MGY Oct 27 '16 at 08:48