30

When I make any iOS 8 Today Extension, there is an empty space on the left of approximately 48px, even if in Interface Builder I place a label on the left side at x=0.


on xcode on the simulator


I have seen that some apps, however, use a full-width widget.


other apps


How can I achieve something similar?

Thanks!


UPDATE: SOLVED

I put here the sample code because I guess it will be useful to someone. As suggested by @matteo-lallone, the correct way to do this is:

-(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMa‌​rginInsets{
return UIEdgeInsetsZero;
}
Antonio Giarrusso
  • 810
  • 1
  • 9
  • 19

2 Answers2

38

Straight from the docs:

A Today widget created using the Xcode Today template includes Auto Layout constraints for standard margin insets. To get the inset values for your calculations, implement the widgetMarginInsetsForProposedMarginInsets: method.

Source: App Extension Programming Guide - Today

Yaroslav Admin
  • 13,880
  • 6
  • 63
  • 83
Matteo Lallone
  • 511
  • 6
  • 7
  • 5
    Thank you, as you suggested I added this code and the problem was solved! -(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets{return UIEdgeInsetsZero;} – Antonio Giarrusso Sep 23 '14 at 12:50
  • 1
    Your link is dead. Take this one [NotificationCenter.html](https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/NotificationCenter.html#//apple_ref/doc/uid/TP40014214-CH11-SW5) – Felix Sep 23 '14 at 19:54
  • Thanks @Felix, it was fine when I posted it! Updated. – Matteo Lallone Sep 24 '14 at 17:02
23

I can supplement the swift version

func widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets {
    return UIEdgeInsetsZero
}

for oc

-(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets {
    return UIEdgeInsetsZero
}

hope it can help someone.

JZAU
  • 3,550
  • 31
  • 37