How to set the height of a Today Widget Extension?

后端 未结 6 1823
心在旅途
心在旅途 2020-12-12 18:13

How can i change the height of my App\'s Today Extension in the Notification Center?

I tried it with the Interface Builder and with Code, the Interface Builder Displ

6条回答
  •  攒了一身酷
    2020-12-12 18:35

    There are two ways to display Today extension:

    1. Compact Mode (fixed height for Widget)
    2. Expand Mode (Variable height for Widget)

    Whatever code you do to change the height of extension in Compact mode will not make any difference. So you need to change the mode from compact to Expand Mode.

    // 1. Load This in viewDidLoad:
    
    override func viewDidLoad() {
      super.viewDidLoad()
      self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
    }
    
    // 2. Implement another widget protocol
    
    func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize){
      if (activeDisplayMode == NCWidgetDisplayMode.compact) {
        self.preferredContentSize = maxSize;
      }
      else {
        self.preferredContentSize = CGSize(width: 0, height: 200);
      }
    }
    

    You can refer WWDC for more updates about App extensions

提交回复
热议问题