1

I'm currently trying to create a today extension that is compatible with the old-style today extension as well as the new style widget in iOS 10.

I am not using storyboards, and so I need to create and set the height and width of the widget's view in the view controller class. This is fine in iOS 10 - widgetMaximumSizeForDisplayMode can be used to grab the width and height of the widget on any device.

However i'm struggling to figure out how to do this for iOS 8 / 9 as widgetMaximumSizeForDisplayMode is only available from iOS 10 onwards. Sometimes the today extension width is simply the width of the device as below:

iPhone 6 today view

But for other devices like the ipad the width of the widget is only a certain width on the screen.

iPad Air today view

Is there a built in method to grab the today-extension width in iOS 8 / 9 ?

Rachel Unthank
  • 302
  • 2
  • 7

2 Answers2

2

Have you tried with the override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) method in the view controller for the today extension?

It is supported from iOS 8 and above and you will get the new size on rotations too.

https://developer.apple.com/reference/uikit/uicontentcontainer/1621466-viewwilltransitiontosize

dadederk
  • 315
  • 2
  • 11
1

The width is always the same for a given device/orientation--you can't set it. But if you need to read it in order to determine the height for that width, you can just check view.bounds.width.

Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92
  • I'm setting the view bounds myself (as i'm not using storyboards so i'm creating the view manually) so I need to know the width of the today extension area before I can set it. iOS 10 satisfies this with the 'widgetMaximumSizeForDisplayMode' method but I can't figure out how to get this width when using iOS 8 / 9. – Rachel Unthank Nov 24 '16 at 10:17