Изображение в приложении настолько маленькое, и в нем так много пустых ячеек, как я могу сделать мое изображение большим, чтобы оно могло поместиться на половине экрана моего телефона? - PullRequest
1 голос
/ 23 апреля 2019

Изображение при просмотре крошечное. Как сделать его наполовину меньше моего телефона?

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
    }
}

Ответы [ 2 ]

0 голосов
/ 26 апреля 2019

Вы должны реализовать метод делегата TableView.

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
       return UIScreen.main.bounds.height/2
    }
  1. убедитесь, что ваш FrameView Frame равен ScreenSize
  2. , убедитесь, что ваш размер imageView равен размеру ячейки TableView
0 голосов
/ 23 апреля 2019

Если у вас есть пользовательская ячейка ImageCell

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

Не установить свойство сборки imageView суперкласса UITableViewCell

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

, но вместо этого создайте imageView, добавьте надлежащие ограничения внутри метода init этого класса и используйте его с kingfisher

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...