【发布时间】:2014-02-26 14:06:00
【问题描述】:
如何以编程方式在情节提要中实现以下约束?
【问题讨论】:
-
这个库看起来很糟糕github.com/iMartinKiss/KeepLayout
标签: ios user-interface storyboard
如何以编程方式在情节提要中实现以下约束?
【问题讨论】:
标签: ios user-interface storyboard
有很多不同的方法可以做到这一点。
可能最简单的方法是使用 Visual Format Language https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html
使用它,您可以使用文本“绘制”布局,它会应用约束。
这样的……
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[tableView]-|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(tableView)]];
您可以使用 VFL 做很多不同的事情。
最好的办法是查看文档或购买书籍。 (我会推荐 Ray Wenderlich 的 iOS7 by Tutorials)。我和他没有关系,但我买了这本书并从那里学习了 AutoLayout。
【讨论】:
reason: 'Unable to parse constraint format: tableView is not a key in the views dictionary. |-[tableView]-| 如何将 tableView 添加到视图字典。顺便说一句,tableView 在故事板中实现。
_tableView 作为你的变量名(所以整个事情将是 [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[_tableView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]]; )。