使用 PinLayout 制作网格视图
Making a grid view using PinLayout
使用https://github.com/layoutBox/PinLayout
我正在尝试制作网格视图。
该视图将包含任意数量的列和行。
行的大小将根据超级视图的宽度和高度根据内容调整大小以适应标签的内容,文本需要贴在视图的顶部,这意味着如果其中一个标签需要 100 点高,下一个只需要 50 点,它自己下面有 50 点 space。基本上,如果标签覆盖了整个高度,这将创建一个顶部食物而不是中心食物。在布局中,我让它有一个底部约束 == 0 或更大。
到目前为止,我得到的只是一个视图容器,所有行都位于原点 x=0,y = 0
行是包含标签的视图,它们堆叠在容器视图中。
我将行放在视图中(容器/table),目前仍然使用布局约束设置标签(至少在我正确填充行之前)。
if let previousView = inView.subviews.last
{
inView.addSubview(rowView)
rowView.pin.below(of: previousView).horizontally().bottom().wrapContent(WrapType.vertically).width(100%)
}
else
{
inView.addSubview(rowView)
rowView.pin.all().wrapContent(WrapType.vertically).width(100%)
}
你应该仔细阅读PinLayout的文档。
请查看 introduction example.
PinLayout doesn't use auto layout constraints, it is a framework that manually layout views. For that reason, you need to update the layout inside either UIView.layoutSubviews() or UIViewController.viewDidLayoutSubviews() to handle container size's changes, including device rotation. You'll also need to handle UITraitCollection changes for app's that support multitasking. In the example above PinLayout's commands are inside UIView's layoutSubviews() method.
使用https://github.com/layoutBox/PinLayout
我正在尝试制作网格视图。 该视图将包含任意数量的列和行。
行的大小将根据超级视图的宽度和高度根据内容调整大小以适应标签的内容,文本需要贴在视图的顶部,这意味着如果其中一个标签需要 100 点高,下一个只需要 50 点,它自己下面有 50 点 space。基本上,如果标签覆盖了整个高度,这将创建一个顶部食物而不是中心食物。在布局中,我让它有一个底部约束 == 0 或更大。
到目前为止,我得到的只是一个视图容器,所有行都位于原点 x=0,y = 0
行是包含标签的视图,它们堆叠在容器视图中。
我将行放在视图中(容器/table),目前仍然使用布局约束设置标签(至少在我正确填充行之前)。
if let previousView = inView.subviews.last
{
inView.addSubview(rowView)
rowView.pin.below(of: previousView).horizontally().bottom().wrapContent(WrapType.vertically).width(100%)
}
else
{
inView.addSubview(rowView)
rowView.pin.all().wrapContent(WrapType.vertically).width(100%)
}
你应该仔细阅读PinLayout的文档。 请查看 introduction example.
PinLayout doesn't use auto layout constraints, it is a framework that manually layout views. For that reason, you need to update the layout inside either UIView.layoutSubviews() or UIViewController.viewDidLayoutSubviews() to handle container size's changes, including device rotation. You'll also need to handle UITraitCollection changes for app's that support multitasking. In the example above PinLayout's commands are inside UIView's layoutSubviews() method.