如何让UIImage只在特定区域伸展

如何让UIImage只在特定区域伸展

本文介绍了如何让UIImage只在特定区域伸展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var contentImageView:UIImageView!{
didSet {
contentImageView.image!.resizableImageWithCapInsets(UIEdgeInsets(top:5,left:5,bottom:5,right) :5))
}
}

我在搜索后尝试过这段代码在互联网上。



但它不起作用,结果是:





有没有更好的实施方式?

解决方案

Xcode .xcassets中有一个时尚的选项。您可以选择图像并从那里切片,以便它只在下面的特定部分中可以呈现图像,请浏览此选项。



  1. 为了您的目的,只需为聊天气泡选择中间选项(垂直和水平切片)。 / li>

  1. 顶部图像是带切片的图像。底部图像是图片没有
    切片。

Borrowed Bhavin的图片用于演示:D


var contentImageView: UIImageView!{
    didSet{
        contentImageView.image!.resizableImageWithCapInsets(UIEdgeInsets(top: 5,left: 5,bottom: 5,right: 5))
    }
}

I have tried this code after searching in the Internet.

But it didn't work and the result is:

Are there any better ways to implement?

解决方案

There is a sleek option in Xcode .xcassets. You can select the images and slice it from there so that it's strechable in specific parts only below are the images please explore this option.

  1. For your purpose just select the middle option (slice vertically and horizontally) for chat bubble.
  1. After Slicing.
  1. Top Image is image with slicing. Bottom image is image withoutslicing.

Borrowed Bhavin's Image for demonstration :D

这篇关于如何让UIImage只在特定区域伸展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:12