ios - 使用 Aspect Fit 时如何去除图像中的空白区域?

标签 ios swift

我在tableview
中显示数据 在图像的Content Mode中,我选择了Aspect Fit
但是我得到了这样的东西

使用background.red
如何去除图片周围的空白区域?
我试图找到一些答案,但没有成功
请帮忙

当我使用 aspectFill 时

我使用此代码显示来自 url 的图像
我使用 Kingfisher

 cell.image_of_new.kf.indicatorType = .activity
    cell.image_of_new.kf.setImage(
        with: url,
        placeholder: UIImage(named: "placeholderImage"),
        options: [
            .scaleFactor(UIScreen.main.scale),
            .transition(.fade(1)),
            .cacheOriginalImage
        ])
    {
        result in
        self.tableview.beginUpdates()
        self.tableview.endUpdates()
    }

最佳答案

Aspect fit 的设计目的是在图像的形状与您绘制它的框架不同时留出空白。

“方面”部分意味着它不会拉伸(stretch)图像以适应目标框架。

“适合”部分意味着它将被绘制,以便源图像的每个部分都适合目标框架。没有任何东西被剪掉。

您的目标框架高而瘦(纵向),您的图像宽(风景)。要将其绘制到高而瘦的框架中而不拉伸(stretch)或裁剪,您将在顶部和底部留有空白。

相比之下,纵横比填充会在不扭曲源图像的情况下将图像绘制到目标矩形中,但会剪掉源图像的部分内容。

关于ios - 使用 Aspect Fit 时如何去除图像中的空白区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56262320/

相关文章:

ios - 使用 Parse 获取用户位置

android - 将 Android SQLite 移植到 iOS

ios - 向 CAShapeLayer 添加渐变

ios - #define 在 Objective-C 的头文件中

ios - UILabel 未使用 UITableViewCell 自定义类 Swift 进行更新

ios - 反馈振动像苹果呼吸一样 swift

ios - UITableView insertRows(位于: indexPath) returns error of invalid number of rows

ios - Swift - 将 Int 保存到核心数据只能工作一次

Swift:使用泛型使函数通用?

ios - Swift - 无法将值成功传递给接下来呈现的 ViewController