I get different to the top and bottom of the cell when I use UIListContentView in a subclass versus if I use UICollectionViewListCell directly.
Here's how I setup directly UICollectionViewListCell:
Here's how I use it in my subclass:
Initialize it
Setup the views:
and then lastly configure it:
/best regards, David
Here's how I setup directly UICollectionViewListCell:
Code Block let reg = UICollectionView.CellRegistration<UICollectionViewListCell, EventCellViewModel> { cell, indexPath, model in var content = cell.defaultContentConfiguration() content.text = model.titleText content.secondaryText = model.subtitleText var accessories: [UICellAccessory] = [.disclosureIndicator(displayed: .always, options: .init(tintColor: .nicePurpleColor))] accessories.append(.customView(configuration: .init(customView: UIImageView(image: UIImage(systemName: "bell")), placement: .trailing()))) cell.accessories = accessories cell.contentConfiguration = content }
Here's how I use it in my subclass:
Initialize it
Code Block private lazy var listContentView = UIListContentView(configuration: defaultListContentConfiguration())
Setup the views:
Code Block private func setupViewsIfNeeded() { guard accessories.isEmpty else { return } accessories = [ .disclosureIndicator(displayed: .always, options: .init(tintColor: .nicePurpleColor)), .customView(configuration: .init(customView: sswitch, placement: .trailing())) ] contentView.addSubview(listContentView) listContentView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ listContentView.topAnchor.constraint(equalTo: contentView.topAnchor), listContentView.leftAnchor.constraint(equalTo: contentView.leftAnchor), listContentView.rightAnchor.constraint(equalTo: contentView.rightAnchor), listContentView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), ]) }
and then lastly configure it:
Code Block override func updateConfiguration(using state: UICellConfigurationState) { setupViewsIfNeeded() var content = defaultListContentConfiguration().updated(for: state) content.text = state.viewModel?.titleText content.secondaryText = state.viewModel?.subtitleText content.axesPreservingSuperviewLayoutMargins = [.both] listContentView.configuration = content sswitch.isOn = state.viewModel?.isEnabledForCalendar ?? false }
/best regards, David