【问题标题】:Xcode 7 : set top constraint for CollectionView for iPhone 6S plusXcode 7:为 iPhone 6S plus 的 CollectionView 设置顶部约束
【发布时间】:2016-12-22 15:00:03
【问题描述】:

我想根据设备类型设置不同的约束。 约束将设置为 b/w CollectionView 和 Label (Username)

例如。 iPhone 4 will have top: 2 left: 0 right: 0 and bottom:0

iPhone 6S Plus will have top: 15 left: 0 right: 0 and bottom:0

如何在 Storyboard 中设置?

【问题讨论】:

  • 在 IB 中使用 size-classes,它可以为您完成这项工作。

标签: ios storyboard constraints xcode7 nslayoutconstraint


【解决方案1】:

您可以为顶部约束创建一个出口并更改代码中的值

@property (weak, nonatomic) IBOutlet NSLayoutConstraint    
                                    *collectionViewTopSpaceConstraint;

-(void)viewDidLoad
{
    [super viewDidLoad];

    //iPhone 6 plus
    if(CGRectGetHeight(self.view.frame) == 736.0)
    {
       self.collectionViewTopSpaceConstraint.constant = 10; // some constant
    }



}

【讨论】:

  • size-classes 是解决此类问题的更优雅的方法。你的建议有点昨天。
猜你喜欢
  • 1970-01-01
  • 2016-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多