问题描述
这是我的故事板
我使用的是自动布局,而不是使用尺寸等级.
I'm using autolayout, and NOT using size classes.
当我在 iPhone 5s 上运行它时,它运行良好.(纵向和横向)
When I ran it on iPhone 5s, it works fine.(both portrait and landscape)
但是当我在 iPhone 6 plus(纵向)上运行它时,它没有正确对齐.
But when I ran it on iPhone 6 plus (portrait), it's not aligning properly.
在 iPhone 6 plus(横向)上,情况更糟.
on iPhone 6 plus (landscape), it's worse.
我知道我可以使用 -widgetMarginInsetsForProposedMarginInsets:
来设置边距,但在这种情况下,我需要为每个设备自定义边距.那太可怕了:(
I know I can use -widgetMarginInsetsForProposedMarginInsets:
to set the margin, but in that case I will need to customize the margin for every device. That would be horrible :(
那么有没有办法让子视图与标题对齐不那么痛苦?
So is there a way to align the subview to the title less painfully?
推荐答案
看来你得手动设置了.为此,您可以创建一个约束,然后为其指定一个 IBOutlet,并根据设备/方向设置常量.
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 加纵向 - 5(15 像素)
- 6 加横向 - 34 (102 像素)
你可以从扩展视图的大小中找到你需要的那个,对于竖屏 iPhone 6 来说是 414 pt.
You can find which one you need from the size of the extension view, which is 414 pt for a portrait iPhone 6.
这篇关于iOS 8 Today 小部件对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!