创建一个如iOS图片所示的视图

时间:2018-07-31 06:20:05

标签: ios iphone uicollectionview

我正在创建一个应用,需要以这种格式显示数据Data representation

现在,它在UITableView内部,比方说它是UITableViewCell。

我在想做什么:-

1. Lets create a UICollectionView inside the UITableViewCell, this will have 
   3 rows. Every row will contain another UICollectionView where I will put 
   the data
   FLow will be like this :-
   UITableView -> UITableViewCell -> UICollectionView -> UICollectionViewCell -> UICollectionView -> UICollectionViewCell

2. create a UICollectionView inside the UITableViewCell, this will have 
       3 rows. Now I will create a view which contains data as whole and put it on cell. Height will be calculated programatically and view is put inside UICollectionViewCell

其他解决方案是这样的,但是我对自己想到的解决方案不满意。

如果有人知道适当的解决方案来执行此操作。让我知道。我更喜欢做得更好。

如果您需要更多详细信息,请告诉我

2 个答案:

答案 0 :(得分:1)

创建一个UICollectionViewUICollectionViewCell添加到情节提要中的视图 将Vertical UIStackView添加到具有属性Fill, and Equal Spacing的单元格中。 将布局约束添加到top,left,right,bottom的单元格中。

现在在cellForRowAtIndexPath函数中,您可以向addArrangedSubviews添加尽可能多的UIStackView

自定义Cell覆盖函数sizeForItemAtIndexPath的大小

答案 1 :(得分:0)

我已经很笨拙了。

这是UITableView中的UITableViewCell,将UICollectionView放在此单元格中,并具有3个UICollectionViewCell。

创建UICollectionViewCell以使其看起来像图片一样的逻辑。

1. Use label1 and make it look like the header.
2. for all the subData make a label, make it multiline and when we are passing the data in the label append newLine to every single word.

Label1.text -> "Skill"
Label2.text = "Swimming\n Running\n surfing\n athletic"

现在我们可以获取标签的高度,该高度将成为UICollectionViewCell的高度。 我发现这是制作此类屏幕的最简单方法。