Ниже код работает, но когда идет длинный текст, он обрезает часть текста, отображаемого в соответствии с шириной рамки просмотра, например replacing it with abstractions or using data normalization to avoid redundancy.
replacing it with abstractions or using data n
показ другого содержимого не отображается
class AyatWordByWordViewController : UIViewController {
let celled = "celled"
var texts : [String] = ["Don't", "repeat", "yourself", "is a principle", "of", "software development", "aimed", "at", "reducing", "repetition of software patterns", "replacing it with abstractions or using data normalization to avoid redundancy."]
//word by work
var collectionView : UICollectionView!
override func viewDidLoad(){
let alignedFlowLayout = UICollectionViewFlowLayout()
alignedFlowLayout.scrollDirection = UICollectionView.ScrollDirection.vertical
collectionView = UICollectionView(frame: .zero, collectionViewLayout: alignedFlowLayout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(AyatTableViewWordByWordItemCell.self, forCellWithReuseIdentifier: celled)
collectionView.backgroundColor = UIColor.clear
self.view.addSubview(collectionView)
collectionView.anchor(view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, topConstant: 150, leftConstant: 10, bottomConstant: 0, rightConstant: 10, widthConstant: 0, heightConstant: 0)
if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
// flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
flowLayout.estimatedItemSize = CGSize(width: 1, height:1)
}
}
}
extension AyatWordByWordViewController : UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return texts.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier:celled, for: indexPath) as! AyatTableViewWordByWordItemCell
cell.subTitleLabel.text = texts[indexPath.item]
cell.backgroundColor = UIColor.blue
return cell
}
}
ячейка:
public func fillSuperview() {
translatesAutoresizingMaskIntoConstraints = false
if let superview = superview {
leftAnchor.constraint(equalTo: superview.leftAnchor).isActive = true
rightAnchor.constraint(equalTo: superview.rightAnchor).isActive = true
topAnchor.constraint(equalTo: superview.topAnchor).isActive = true
bottomAnchor.constraint(equalTo: superview.bottomAnchor).isActive = true
}
}
Использована
subTitleLabel.fillSuperview()
здесь вывод iPhoneX OS12.2