Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Because SwiftUI has no UICollectionView-like controls,so I used UIKit instead.

According to interfacing-with-uikit, I know how SwiftUI interacts with UIKit, but I want to further use SwiftUI to encapsulate UICollectionViewCell, and use SwiftUI to fill the content of UICollectionViewCell, how can I do that.

As far as I know List in SwiftUI are encapsulated according to UITableView, I want SwiftUI to do the same with UICollectionView,I don't want to use some tripartite libraries to do this, I want to learn the secrets

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
181 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming you have CellContentView SwiftUI view, you can integrate it in UICollectionViewCell using something like the following

if let cellContent = UIHostingController(rootView: CellContentView()).view {
    cell.contentView.addSubview(cellContent)

    cellContent.leadingAnchor.constraint(equalTo: cell.leadingAnchor).isActive = true
    cellContent.trailingAnchor.constraint(equalTo: cell.trailingAnchor).isActive = true
    cellContent.topAnchor.constraint(equalTo: cell.topAnchor).isActive = true
    cellContent.bottomAnchor.constraint(equalTo: cell.bottomAnchor).isActive = true
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...