Custom “resizable image” drawing in iOS

佐手、 提交于 2019-12-04 03:39:32

问题


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.

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:

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.

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!


回答1:


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.



来源:https://stackoverflow.com/questions/20117787/custom-resizable-image-drawing-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!