Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karigrooms/80a7b28af228ff802ca1e238e0657ba3 to your computer and use it in GitHub Desktop.
Save karigrooms/80a7b28af228ff802ca1e238e0657ba3 to your computer and use it in GitHub Desktop.
Blog post: SwiftUI with UICollectionView - 17. UIButton positioned on top of the SwiftUI View
import SwiftUI
import UIKit
class MyCollectionViewCell: SwiftUICollectionViewCell<Card> {
static var reuseIdentifier = "MyCollectionViewCell"
typealias Content = Card.Content
lazy var heartButton: UIHeartButton = {
return UIHeartButton()
}()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(heartButton)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(with content: Content, parent: UIViewController) {
embed(in: parent, withView: Card(content: content))
host?.view.frame = self.contentView.bounds
// UIButton layout
heartButton.frame = CGRect(x: contentView.bounds.width - 60, y: 20, width: 40, height: 40)
contentView.bringSubviewToFront(heartButton)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment