问题
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