Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fit width in iOS 8 Today Extensions

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 xcodeon 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;
}
like image 231
Antonio Giarrusso Avatar asked Sep 23 '14 11:09

Antonio Giarrusso


2 Answers

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

like image 54
Matteo Lallone Avatar answered Nov 11 '22 08:11

Matteo Lallone


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.

like image 32
JZAU Avatar answered Nov 11 '22 10:11

JZAU