есть ли возможность показать изображение в Grid в соответствии с шириной экрана в UitableView в Swift - PullRequest
1 голос
/ 17 июня 2019

Я хочу показать 3 изображения подряд uitableview. но если у меня больше 3; это должно быть в следующей строке таблицы.

Вот код

 var abc = fileimage.count
for i in 0..<abc
{
    var tempimage = UIImage(named: fileimage[i])
    var actualwidth = UIScreen.main.bounds.width - 32
    var noofitem = actualwidth/100

    imageview.addSubview(fileimageview)
    fileimageview.easy.layout(Height(<=100))
    fileimageview.easy.layout(Width(<=100))

    fileimageview.easy.layout(Top(0),Left(0 * CGFloat(i) * 100),Bottom(0))
    fileimageview.image = tempimage
}

Ответы [ 2 ]

0 голосов
/ 17 июня 2019

Вот пример, который вы можете получить, разделив ширину представления вашей коллекции на 3.

  class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {    

      @IBOutlet weak var collectionViewFlowLayoutAction: UICollectionViewFlowLayout!
      @IBOutlet weak var otherProvidersCollectionView: UICollectionView!

        override func viewDidLoad() {
            super.viewDidLoad()

          //Customize these properties per your need

            collectionViewFlowLayoutAction.itemSize = CGSize(width: otherProvidersCollectionView.frame.size.width/3.0, height: otherProvidersCollectionView.frame.size.width/3.0) // this will show only 3 grid per row according to your collectionview width.

            collectionViewFlowLayoutAction.minimumInteritemSpacing = 1.5 
            collectionViewFlowLayoutAction.minimumLineSpacing = 1.8
            collectionViewFlowLayoutAction.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
            otherProvidersCollectionView!.collectionViewLayout = collectionViewFlowLayoutAction
     }
}
0 голосов
/ 17 июня 2019

Вот пример CollectionView с разметкой сетки.

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
        var fileimage = [UIImage]()
        @IBOutlet weak var showPhotosCollectionView: UICollectionView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.showPhotosCollectionView.delegate = self
        self.showPhotosCollectionView.dataSource = self
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return fileimage.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as? Cell
        cell!.imageView.image = self.fileimage[indexPath.row]
        return cell!
    }
}

extension ViewController : UICollectionViewDelegateFlowLayout {
    //1
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout:
        UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let screenSize: CGRect = UIScreen.main.bounds
        let screenWidth = screenSize.width
        return CGSize(width: (screenWidth/3)-6, height: (screenWidth/3)-6);
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...