Reputation: 430
I would like to modify the height of the View in Xib Size Inspector flexibly in the code.
I also want to modify the Height Equals in Constraints in the UICollectionView in Xib.
Short Code :
class ShopImagesViewCell: UITableViewCell
{
@IBOutlet weak var imageCollectionView: UICollectionView!
override func awakeFromNib()
{
super.awakeFromNib()
// ......
}
}
extension ShopImagesViewCell
{
func setView(urls : [String], isZzip : Bool)
{
self.imageCollectionView.delegate = self
self.imageCollectionView.dataSource = self
self.imageCollectionView.regCells(cells:
["ShopImageCollectionViewCell","ShopNonImageCollectionViewCell"])
// ......
}
}
extension ShopImagesViewCell : UICollectionViewDelegateFlowLayout, UITableViewDelegate
{
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return CGFloat(291) // It does not work.
}
}
When Xib is first loaded, it is executed only once to fit in size.
Modifying Xib height length in code and modifying the Height Equals of Constraintsd in UICollectionView in code.
Please tell me where I should use the code.
Upvotes: 2
Views: 101
Reputation: 8011
According to you pasted code, it seems that you placed a custom UITableViewCell
into the nib. Assumed on that, you cannot set height directly without the help of UITableViewDelegate
.
Where the UITableViewDelegate
is implemented or you intended to implement add this delegate method
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// you have the indexPath based on which you can set the height dynamically, based on the cell position.
// return your intended height here
}
Hope it helps.
Upvotes: 2