gpt4 book ai didi

ios - 如何让 UIImageView 填充 UITableViewCell?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:12:49 25 4
gpt4 key购买 nike

这是我的第一篇文章,所以如果有什么我应该做的不同,请告诉我!

我正在制作一个照片应用程序,我希望照片填充 UITaleViewCells,并扩展单元格以适合图像。


我一直在努力让它工作,我用谷歌搜索了所有我能做的事情,看了一些 youtube 视频,但我找不到任何与 UIImageView 一起工作的视频。这是我现在正在使用的代码:

override func viewWillAppear(_ animated: Bool) {
tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableViewAutomaticDimension
}

在 UIImageView 上我有这些约束:Bottom MarginTop MarginTrailing MarginLeading Margin,当我运行我的应用程序时,我发现这真的很奇怪图片顶部和底部的空间。


下面是一些截图:

Full Main.storyboard screenshot

iOS simulator screenshot

最佳答案

好吧,我建议您为此尝试使用 UICollectionView,因为对于此类布局,最好使用 Collection View 而不是 Table View,试试这个(tempArr 表示您的图像数组),

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
// create a cell size from the image size, and return the size

let picHeight = tempArr[indexPath.row].valueForKey("imgHeight") as! String
let picWidth = tempArr[indexPath.row].valueForKey("imgWidth") as! String
var picHeightFloat :CGFloat!
var picWidthFloat :CGFloat!

if let n = NSNumberFormatter().numberFromString(picHeight) {
picHeightFloat = CGFloat(n)
}
if let q = NSNumberFormatter().numberFromString(picWidth) {
picWidthFloat = CGFloat(q)
}

let imageSize = CGSize(width: picWidthFloat, height: picHeightFloat)


return imageSize
}

关于ios - 如何让 UIImageView 填充 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43025403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com