Uitableview 将标签放置在collectionview内,并将collectionview进一步放置在具有动态高度的tableview单元格内
tableview单元格内的collectionview未适应动态高度。正如我所希望的,tableview单元格应采用collectionview单元格内标签的大小标签的约束为前导、试算、顶部、底部为5 wrt contentView collectionview单元格Uitableview 将标签放置在collectionview内,并将collectionview进一步放置在具有动态高度的tableview单元格内,uitableview,swift3,uicollectionview,swift4,intrinsic-content-size,Uitableview,Swift3,Uicollectionview,Swift4,Intrinsic Content Size,tableview单元格内的collectionview未适应动态高度。正如我所希望的,tableview单元格应采用collectionview单元格内标签的大小标签的约束为前导、试算、顶部、底部为5 wrt contentView collectionview单元格 class myRewardsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet we
class myRewardsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var rewardsTableView: UITableView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "rewardsTV_cell", for: indexPath) as! rewardsCarouselTableViewCell
cell.layoutIfNeeded()
cell.carouselRewardsCV.reloadData()
cell.rewardCarouselHeight.constant = cell.carouselRewardsCV.collectionViewLayout.collectionViewContentSize.height
return cell
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
rewardsTableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
rewardsTableView.estimatedRowHeight = 300
rewardsTableView.rowHeight = UITableView.automaticDimension
// Do any additional setup after loading the view.
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
}
}
类DynamicLightRewardsCollectionView:UICollectionView{
override func layoutSubviews() {
super.layoutSubviews()
if bounds.size != intrinsicContentSize {
self.invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
return collectionViewLayout.collectionViewContentSize
}
}
extension rewardsCarouselTableViewCell:
UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView.frame.width, height: collectionView.frame.height)
}
override func layoutSubviews() {
super.layoutSubviews()
if bounds.size != intrinsicContentSize {
self.invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
return collectionViewLayout.collectionViewContentSize
}