0

I have this irritating issue with widgets that it trims the content of my view in the landscape mode. I have put the content size statically but it doesn't work. Does Apple restrict the widget to have a specific height in landscape? Apple's interface guidelines says it's not recommended but is it doable?

Edit: enter image description here

Ashraf Tawfeeq
  • 3,036
  • 1
  • 20
  • 34

2 Answers2

1

There is a height limit for today widgets on iOS. The max height is (screen size) - (notification center UI height). Whatever's left after the notification center draws its UI is left for widgets. That's going to be different in landscape than in portrait.

Unfortunately this limit is not documented, nor is there any way to look it up at run time. If you request a larger size, you'll get something less than you requested, but there's no way to ask what the limit is. [And if anyone from Apple reads this, please see rdar://18408718, "Today extensions have undocumented, hard to discover size limits"]

In some cases the notification center seems to impose a lower height limit. This looks like a bug to me but there's no way around it for now.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • That's what I have come to too. But I found something that may interest you. I will edit my answer now. – Ashraf Tawfeeq Feb 05 '15 at 17:25
  • I've seen that. The annoying thing is that the documentation says you should "avoid" having the widget too tall, but the run time environment enforces it as a rule while also refusing to tell you what the limit it. – Tom Harrington Feb 05 '15 at 17:30
  • Exactly! Like you said, seems like a undocumented rule or maybe a bug. – Ashraf Tawfeeq Feb 05 '15 at 17:32
0

With Swift 3 & IOS10 : Add this method to your widget controller and you will get the maxsize

@available(iOSApplicationExtension 10.0, *)
    func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize){
        if (activeDisplayMode == NCWidgetDisplayMode.compact) {
            self.preferredContentSize = maxSize;
            // hide or show what you want
            messageLabel.isHidden = false
            textLabel.isHidden = true
        }
        else {

            self.preferredContentSize = CGSize(width: 0, height: (maxSize.height - 100) // personnaly I remove 100 to make it easier fo the user to see all the widget

            messageLabel.isHidden = true
            textLabel.isHidden = false
        }
}
tolbard
  • 1,273
  • 15
  • 20