iOS 8 Today widget alignment issue

不问归期 提交于 2019-12-05 02:45:36

Looks like you have to set it manually. You can do this by creating a constraint, then specifying an IBOutlet to it, and setting the constant depending on the device/orientation.

For reference, here are the margins I found you needed:

  • 5S - 1 (2px)
  • 6 - 1 (2px)
  • 6 plus portrait - 5 (15px)
  • 6 plus landscape - 34 (102px)

You can find which one you need from the size of the extension view, which is 414 pt for a portrait iPhone 6.

Setting the edge insets to zero should fix the problem:

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

You need to customise the widget margins:

- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets;

Documentation: https://developer.apple.com/library/ios/documentation/NotificationCenter/Reference/NCWidgetProviding_Protocol/index.html

Fixes for some devices. Requires Ericas UIDevice-Extension.

- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets
{
    defaultMarginInsets.bottom = 0;

    if ([UIDevice.currentDevice.modelIdentifier containsString:@"iPhone7,1"] && self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
        defaultMarginInsets.left += 5;
    } else if ([UIDevice.currentDevice.modelIdentifier containsString:@"iPhone7,1"] && self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular) {
        defaultMarginInsets.left += 34;
    } else {
        defaultMarginInsets.left += 1;
    }

    return defaultMarginInsets;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!