hostingController.view.fillSuperview() doesn't work but This is Work , try This
struct ContactRowView: View {
var body: some View {
HStack{
Image(systemName: "person.fill")
Text("Some Contacts")
Spacer()
Image(systemName: "star")
}
}
}
class ContactCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
// backgroundColor = .red
let hostingController = UIHostingController(rootView: ContactRowView())
self.addSubview(hostingController.view)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
hostingController.view.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
hostingController.view.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
hostingController.view.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
hostingController.view.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}