在ScrollView中添加CollectionView

时间:2019-12-13 06:39:53

标签: swift uicollectionview uiscrollview uicollectionviewcell programmatically

我在实现UI时遇到问题。我实际上想在滚动视图的末尾添加一个集合视图。我不完全知道该怎么做,我觉得自己被卡住了...

这是我的电话,用于在滚动视图中添加视图。

if training?.description != nil {
  //add description  
  addTraining(description: (training?.description)!)
}
if training?.question1 != nil{
  addTraining(question1: (training?.question1)!)
}
if training?.question2 != nil{
  addTraining(question2: (training?.question2)!)
}
// ADD COLLECTION VIEW AT BOTTOM

这里是各个功能。

private func addTraining(description: String) {
    trainingDescriptionTitle.text = "Description"
    trainingDescriptionContent.text = description
    trainingDescriptionContent.sizeToFit()
    trainingDescriptionContent.frame.size = CGSize(width: view.frame.width - 10, height: trainingDescriptionContent.frame.height)
    trainingDescriptionContainerView.addView(newView: trainingDescriptionTitle)
    trainingDescriptionContainerView.addView(newView: trainingDescriptionContent)
    scrollView.addView(newView: trainingDescriptionContainerView)
}

private func addTraining(question1: String) {
    trainingQuestion1Title.text = "What You Will Learn"
    trainingQuestion1Content.text = question1
    trainingQuestion1Content.sizeToFit()
    trainingQuestion1Content.frame.size = CGSize(width: view.frame.width - 10, height: trainingQuestion1Content.frame.height)
    trainingQuestion1ContainerView.addView(newView: trainingQuestion1Title)
    trainingQuestion1ContainerView.addView(newView: trainingQuestion1Content)
    scrollView.addView(newView: trainingQuestion1ContainerView)
}

private func addTraining(question2: String) {
    trainingQuestion2Title.text = "Who Should Take This"
    trainingQuestion2Content.text = question2
    trainingQuestion2Content.sizeToFit()
    trainingQuestion2Content.frame.size = CGSize(width: view.frame.width - 10, height: trainingQuestion2Content.frame.height)
    trainingQuestion2ContainerView.addView(newView: trainingQuestion2Title)
    trainingQuestion2ContainerView.addView(newView: trainingQuestion2Content)
    scrollView.addView(newView: trainingQuestion2ContainerView)
}

在scrollView中添加collectionView时,我该怎么做? 感谢任何会回答的人。

这将是结果:

0 个答案:

没有答案