小编Tol*_*ÇÜK的帖子

如何将 UICollectionReusableView 拉伸到安全区域

我试图在 UICollectionView 类中显示 HeaderView,并为此使用 UICollectionReusableView 类。

实际上我在 CollectionView 中显示 HeaderView 但它没有到达安全区域。

我以编程方式使用自动布局,并编写了扩展来做到这一点。

这是我在代码中使用的类和扩展:

import Foundation
import UIKit

private let headerIdentifer = "HeaderCell"

class ProfileController: UICollectionViewController { 
    //MARK: - Properties
    
    //MARK: - Lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        configureProfileCollectionView()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.navigationBar.isHidden = true
        
    }

    //MARK: - Helpers

    func configureProfileCollectionView() {
        collectionView.backgroundColor = .white
        collectionView.register(HeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifer)
    }
}

extension ProfileController {
    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) …
Run Code Online (Sandbox Code Playgroud)

xcode ios autolayout uicollectionview swift

6
推荐指数
1
解决办法
2120
查看次数

标签 统计

autolayout ×1

ios ×1

swift ×1

uicollectionview ×1

xcode ×1