测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2015年4月 |
由 Arthur Ariel Sabintsev 维护。
这是在 UIView
上的一个小 Objective-C 分类,它创建一个可编程 AutoLayout 的 UIView 对象。这个类对于经常在 xibs 和 storyboards 外面进行 AutoLayout 定义的人来说很有用。
只需将 UIView+AutoLayoutView 文件夹拖入您的项目中,并在需要访问其提供的信息的类中引用 UIView+AutoLayoutView.h
即可。
@interface UIView (AutoLayoutView)
+ (instancetype)newAutoLayoutView;
+ (void)updateLayoutForView:(UIView *)view;
@end
+ (instancetype)newAutoLayoutView
{
UIView *view = [self new];
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
return view;
}
+ (void)updateLayoutForView:(UIView *)view
{
[view setNeedsLayout];
[view layoutIfNeeded];
}
@end
// Create an AutoLaoyut view
MyView *myView = [MyView autoLayoutNew]; // Creates a new progrmmatic-AutoLayout ready object
// Update the view after the constraints are set
[UIView updateLayoutForView:myView];
// Create an AutoLaoyut view
let myView = MyView.autoLayoutNew() // Creates a new progrmmatic-AutoLayout ready object
// Update the view after the constraints are set
UIView.updateLayoutForView(myView);