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

我现在把想要显示的图片裁成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.
图片描述

求解决方法。

阅读 4.8k
1 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题