Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get width of iOS today extension

I want to get the width value of my widget / today extension.

I can't use self.view.frame.size.width because it returns the whole screen width and not the actual widget width (on the iPad the width of the extension is not equal to the screen width).

What can I do to get the actual width of the widget?

like image 756
fredpi Avatar asked Mar 22 '15 07:03

fredpi


2 Answers

.............. Don't read self.view.frame in viewDidLoad.

frame = (0 0; 768 1024); // in viewDidLoad

You should read self.view.frame after viewDidAppear

after viewDidAppear, self.view.frame is right value for content.

frame = (0 0; 545 75.5); // in viewDidAppear

like image 88
Mornirch Avatar answered Sep 23 '22 15:09

Mornirch


Instead of viewDidAppear, I found that viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator is triggered automatically when the widget gets resized initially

like image 41
Stephen Avatar answered Sep 22 '22 15:09

Stephen