1

Image is tiny when displayed how can I make it half of the size of my phone?

import UIKit
import Kingfisher

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    @IBOutlet var tableview: UITableView!

    var arrayOfImages = ["https://firebasestorage.googleapis.com/v0/b/starlaxcy.appspot.com/o/myimage.png?alt=media&token=adcfa5ce-5bc3-4a65-bdcd-fb190f4c38d2"]

    override func viewDidLoad() {
        self.tableview.register(ImageCell.self, forCellReuseIdentifier: "ImageCell")
        super.viewDidLoad()
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return arrayOfImages.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ImageCell") as! ImageCell

        let resource = ImageResource(downloadURL: URL(string: arrayOfImages[indexPath.row])!, cacheKey: arrayOfImages[indexPath.row])

        cell.imageView?.kf.setImage(with: resource)

        return cell
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0

If you have a custom cell ImageCell

let cell = tableView.dequeueReusableCell(withIdentifier: "ImageCell") as! ImageCell

Don't set the build in property imageView of the super class UITableViewCell

cell.imageView?.kf.setImage(with: resource)

but instead create an imageView , add proper constraints inside the init method of that class and use it with kingfisher

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

you have to implement TableView delegate's method .

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
       return UIScreen.main.bounds.height/2
    }
  1. make sure your TableView Frame equal to ScreenSize
  2. make sure your imageView size equal to TableView Cell Size
Bhavesh.iosDev
  • 924
  • 9
  • 27