iOS 8 Today小部件对齐问题

时间:2014-09-24 19:41:22

标签: widget ios8 ios8-extension

这是我的故事板

enter image description here

我使用自动布局,而不使用尺寸类。

当我在iPhone 5s上运行时,它运行正常。(纵向和横向) enter image description here

但是当我在iPhone 6 plus(肖像)上运行它时,它没有正确对齐。 enter image description here

在iPhone 6 plus(风景)上,情况更糟。 enter image description here

我知道我可以使用-widgetMarginInsetsForProposedMarginInsets:来设置边距,但在这种情况下,我需要为每个设备自定义边距。那太可怕了:(

那么有没有办法将子视图与标题对齐不那么痛苦?

4 个答案:

答案 0 :(得分:9)

将边缘插入设置为零可以解决问题:

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

答案 1 :(得分:5)

看起来你必须手动设置它。您可以通过创建约束,然后为其指定IBOutlet,并根据设备/方向设置常量来完成此操作。

作为参考,以下是我发现您需要的边距:

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

你可以从扩展视图的大小找到你需要的那个,这对于iPhone 6的肖像来说是414 pt。

答案 2 :(得分:0)

您需要自定义窗口小部件边距:

- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets;

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

答案 3 :(得分:0)

某些设备的修复程序。需要Ericas Title Some text I want to retrieve. Some other text I don't want.

UIDevice-Extension