自定义“可调整大小的图像”在iOS中绘图 [英] Custom "resizable image" drawing in iOS

查看:98
本文介绍了自定义“可调整大小的图像”在iOS中绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIImage API提供了以某些区域被拉伸的方式调整图像大小的方法,而其他区域保持不变 - 非常适合可调整大小的UI元素的背景图像。

The UIImage API provides methods to resize an image in a way that certain areas get stretched, while others remain unaltered - great for background images for resizable UI elements.

现在我正在寻找一种方法来为更复杂的背景图像自定义此行为。

Now I am looking for a way to customize this behavior for more complex background images.

这是 - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets; 的确如此。透明区域保持不变,当视图大小改变时,红色区域会被拉伸。

This is what - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets; does. The transparent areas remain unaltered, the red areas are stretched when the view size is changed.

这就是我想要的 - 对拉伸区域进行更精细的控制:

This is what i want - finer grained control over the areas that are stretched:

我想我必须通过覆盖我的UIView子类的 - (void)drawRect:方法然后使用Quartz来绘制图片。

I guess I'd have to do that by overwriting the -(void)drawRect: method of my UIView subclass and then use Quartz to do the drawing of the image.

我无法弄清楚我必须使用哪种系统API。

I just can't figure out which of the system APIs I would have to use.

有人能给我一个提示如何实现这个目标吗?
提前致谢!

Could anybody give me a hint how to accomplish this? Thanks in advance!

推荐答案

我只想在里面使用三个独立的UIImageViews和resizableImageWithCapInsets。您也可以在drawRect中使用,例如,CGPattern,但在缩放视图时会出现性能问题。

I would just use three separate UIImageViews with resizableImageWithCapInsets inside. You could also so it in drawRect using, for example, CGPattern, but you would have performance issue when scaling the view.

这篇关于自定义“可调整大小的图像”在iOS中绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆