1

I have problem that the today extension is way too big on IOS versions lower that 9. But it is exactly how I want on greater or equal to IOS 10 devices. And also it is misplaced on the IOS 9 devices.

The constraints I have are the following:

  1. Center vertically,
  2. Center horizontally,
  3. Fixed height(200),
  4. Fixed width(200)

This is how it looks on IOS10+

enter image description here

And it looks like this on IOS9

enter image description here

What could cause the issue?

Tarvo Mäesepp
  • 4,477
  • 3
  • 44
  • 92
  • Maybe trying [this](http://stackoverflow.com/questions/39936934/size-problems-by-converting-ios-9-today-extension-to-ios-10) can help you – Papershine Feb 04 '17 at 00:30
  • 1
    According to that page, `self.preferredContentSize.height = 200` should be used to set the height in iOS 9 – Papershine Feb 04 '17 at 00:46
  • Ohh.. you are totally right. I missed the else block :) But still, why it is not centered? – Tarvo Mäesepp Feb 04 '17 at 00:48
  • Then maybe you should set the width smaller... I don't really know – Papershine Feb 04 '17 at 00:50
  • I had also some issues with the layout (programmatically created) of a view in a today extension. I don't know if it will help in this case, but you can try it to setup your constraints in `viewDidAppear(_:)` instead of `viewDidLoad()` http://stackoverflow.com/questions/41761157/today-extension-with-uicollectionview-different-behaviour-compared-to-single-vie – ronatory Feb 04 '17 at 10:38

1 Answers1

2

Try this:

For iOS-8 and iOS-9

func widgetMarginInsets(forProposedMarginInsets defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets
{
    return UIEdgeInsets.zero
}

For iOS-10

It is handled automatically.

For more refer to: https://github.com/pgpt10/Today-Widget

PGDev
  • 23,751
  • 6
  • 34
  • 88
  • Thank you so much!! I was creating a widget in ios 11 and couldn't seem to get my ios 9 widget centered correctly, even though I added all the necessary constraints. – Noah G. Jul 18 '18 at 15:23