Today Extension height for iPad much larger than specified

前端 未结 3 1137
花落未央
花落未央 2021-02-11 12:38

My Today extension needs to have a dynamic height based on the contents the widget is displaying. I was able to achieve this by adding a constraint on my bottom-most element: bo

相关标签:
3条回答
  • 2021-02-11 12:59

    I was facing the same issue. Have you added bottom padding constraint as shown in the image?

    That worked for me.Hope it helps

    0 讨论(0)
  • 2021-02-11 13:15

    Here's how to achieved this:

    1. You should consider your constraint.

    2. Your widgets default margin insets are not properly configured on the way you desired it, so setting this on your own is the only workaround here by calling 'widgetMarginInsetsForProposedMarginInsets:'

    // Update widgets insets

    func widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets {
    
        println(NSStringFromUIEdgeInsets(defaultMarginInsets))
        return UIEdgeInsetsMake(20, 20, 10, 20)
    }
    

    Modified sample file link: Modified file

    0 讨论(0)
  • 2021-02-11 13:20

    I had to hardcode the value of the widget on the viewDidLoad delegate method in order to fix this:

    import UIKit
    import NotificationCenter
    
    class TodayViewController: UIViewController, NCWidgetProviding {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.preferredContentSize = CGSize(width: 0, height: 320)
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题