Dave G Dave G - 1 year ago 172
Swift Question

Today Extension AutoLayout Not Working

My problem is that I cannot figure out how to get my entire extension to display. It should show four rows but it always cuts off like this:

Cut off Today extension

I read some threads and tried preferredContentSize but it doesn't work either:

func widgetPerformUpdate(completionHandler: (@escaping (NCUpdateResult) -> Void)) {
self.preferredContentSize = CGSize(width: 0, height: 400)

What's frustrating it that I shouldn't even need preferredContentSize because I set the auto layout constraints!

autolayout constraints

You'll notice the bottom constraint is a dotted line because it's currently set to a 999 priority but I've tried it at 1000 too.

How do I fix this? Please help!!

Answer Source

I know what you are talking about, I have the same problem.

I seams that your widget cannot be higher than a certain height for your device. But you can enable an expanded mode, where you can toggle between a compact and expanded view of your widget.

I guess it should clean up the today view from too large widgets.

This article will help you: https://forums.developer.apple.com/thread/48930

The important pieces are:

self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded

func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
    if (activeDisplayMode == .compact) {
        self.preferredContentSize = maxSize;
    else {
        self.preferredContentSize = CGSize(width: 359, height: 200)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download