Rachel McGreevy Rachel McGreevy - 1 month ago 21
iOS Question

How to get the width of a today-extension in iOS 8 / 9

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 ?


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.