ios - 如何让大尺寸的image适配到uiimageview里面

 莪鈈稀罕rn 发布于 2022-10-30 02:51

我现在把想要显示的图片裁成1024 X 1024的尺寸。。然后想要放进uiimage里面。
uiimageviewlabeluicollectionviewcell里的properties.
相关的constraints也设置好了的。

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = self.imageCollectionView.dequeueReusableCellWithReuseIdentifier("ImageCollectionViewCell", forIndexPath: indexPath) as! ImageCollectionViewCell
        cell.imageViewContainer.image = self.sourceImages[indexPath.row]
        let imageSize = self.sourceImages[indexPath.row].size
        cell.imageViewContainer.frame = CGRectMake(0.0, 0.0, imageSize.width, imageSize.height)
        cell.imageViewContainer.contentMode = .ScaleAspectFit
        cell.imageViewContainer.clipsToBounds = true
        cell.imageTextField.tag = indexPath.row
        cell.imageTextField.delegate = self
        return cell
    }

上面的方法是UICollectionViewDelegate里面的方法

然后显示的效果是这样的。上下都有spacing.

求解决方法。

1 个回答
  • 不怕麻烦,用 UIGraphics 自定义大小绘制一下,性能最好。
    怕麻烦,看看 UIImageView 的几种图片放缩类型那种适合你。
    不知道有没有 get 到你的点

    2022-10-31 19:41 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有