迅速在tableview上设置图像视图高度

时间:2019-06-18 12:37:25

标签: ios swift tableview

enter image具有imagepicker的Tableview,当在tableview中选择任何单元格以显示图像选择器视图时,当我从选择器中选择将图像显示到tableview的确切单元格中的图像时,一切正常,但是图像显示不同布局,我有很高的显示图像

   func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
            let path = IndexPath(row: self.selectedCell.row, section: 0)
            let cell = Tableview.cellForRow(at: path) as! CustomTableviewCell
            cell.documentImage?.image  = pickedImage
            cell.documentImage?.frame = CGRect()
        }
        Tableview.reloadData()
        picker.dismiss(animated: true, completion: nil)
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableviewCell
        if SegmentController.selectedSegmentIndex == 0
        {
            cell.prooofLable?.text = idProof[indexPath.row]
        }else  if SegmentController.selectedSegmentIndex == 1
        {
            cell.prooofLable?.text = addressProof[indexPath.row]

        }
        return cell
    }

2 个答案:

答案 0 :(得分:0)

希望这对您有帮助

尝试cell.documentImage?.clipsToBounds = true

仍然面临问题,随时与我讨论

答案 1 :(得分:0)

快捷键4

在Storyoard中将ImageView的图像Contentmode模式更改为aspectfitaspectfill,然后在剪辑上打勾以进行绑定。

您也可以通过编程方式执行此操作

cell.documentImage?.clipsToBounds = true
cell.documentImage?.contentMode = .scaleAspectFit

这是您方法中的完整代码。

   func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
            let path = IndexPath(row: self.selectedCell.row, section: 0)
            let cell = Tableview.cellForRow(at: path) as! CustomTableviewCell
            cell.documentImage?.image  = pickedImage
            cell.documentImage?.clipsToBounds = true //clips out the image out of the cell
            cell.documentImage?.contentMode = .scaleAspectFit //fits the streacth view in image
            cell.documentImage?.frame = CGRect()
        }
        Tableview.reloadData()
        picker.dismiss(animated: true, completion: nil)
    }