hello I'm new here trying to make an app with swift. here i am trying to get dynamic cell height along with text size but i am confused, have read about preferredLayoutAttributesFitting but i can't figure it out, maybe someone can help, thank you and i really appreciate your help.
import Foundation
import UIKit
import SnapKit
class MainLv: UIView {
let sampledata: [String] = ["TESTING","TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING TESTING"]
var mainlv: UICollectionView!
var collectionViewFlowlayout = UICollectionViewFlowLayout()
override init(frame: CGRect) {
super.init(frame: frame)
setuplayoutbase()
setuplayout()
}
private func setuplayoutbase() {
self.backgroundColor = .cColorbasegray
self.clipsToBounds = true
self.layer.cornerRadius = 8
self.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
}
private func setuplayout() {
collectionViewFlowlayout.scrollDirection = .vertical
collectionViewFlowlayout.minimumInteritemSpacing = 0
collectionViewFlowlayout.minimumLineSpacing = 1
mainlv = UICollectionView(frame: .zero, collectionViewLayout: collectionViewFlowlayout)
mainlv.register(ViewSubCell.self, forCellWithReuseIdentifier: "CELL")
mainlv.dataSource = self
mainlv.delegate = self
self.addSubview(mainlv)
mainlv.snp.makeConstraints { make in
make.edges.equalTo(self)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}