user1140780
user1140780

Reputation: 988

Swift 3 / iOS 10 Today View Widget

How to show "Show More" button in today widget (similar to news app as attached here)? I found this on Apple but there are some changes in swift 3 / iOS 10. This seems to be like something new in iOS 10.

enter image description here

Upvotes: 2

Views: 3191

Answers (1)

user1140780
user1140780

Reputation: 988

This code did the trick of showing "Show More"

override func viewDidLoad() {
      super.viewDidLoad()

    self.preferredContentSize = CGSize(width: 320, height: CGFloat(items.count)*121 + 44)

    if #available(iOSApplicationExtension 10.0, *) {
        self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded
    } else {
        // Fallback on earlier versions
    }
}

// For iOS 10
@available(iOS 10.0, *)
@available(iOSApplicationExtension 10.0, *)
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
    self.preferredContentSize = (activeDisplayMode == .expanded) ? CGSize(width: 320, height: CGFloat(items.count)*121 + 44) : CGSize(width: maxSize.width, height: 110)
}

Upvotes: 8

Related Questions