uicollectionview remove top padding

后端 未结 5 2030
滥情空心
滥情空心 2020-11-30 14:52

I have a UICollectionView that is the entire view but it lives inside \"view\" (it is not UICollectionViewController). Adding a cell to this collection view shows it in the

5条回答
  •  死守一世寂寞
    2020-11-30 15:38

    You can fix top padding issue by considering one of the following method.

    Method 1: Natural way to fix your problem by setting up your collectionView dimensions properly from StoryBoard.

    Method 2: **Updated**

    You can validate collection frame in viewDidLayoutSubviews or viewWillLayoutSubviews

      override func viewDidLayoutSubviews() {
         collectionView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
    }
    

    Method 3: You can Adjust Scroll View Insets from your StoryBoard Attributes Inspector.

    Method 4: You can fix this issue programatically by adjusting CollectionView contentInset.

    collectionView.contentInset = UIEdgeInsets(top: **Any Value**, left: 0, bottom: 0, right: 0)
    

    Output with top padding 5:

    Output with top padding 44:

    Output with top padding 64:

提交回复
热议问题