UIImage stretchableImageWithLeftCapWidth does not work when drawing in quartz context

I draw an image with removable caps defined as follows:

[bubbleImg stretchableImageWithLeftCapWidth:17 topCapHeight:12]; 

And this works great when inside a UIImageView, but doesn't work when drawing an image like this:

 CGContextDrawImage(context, CGRectMake(x, y, width, height), image.CGImage); 

.. which I kind of suspected would not work. Is there a solution for stretch cover images when drawing in CG context?

+4
source share
1 answer

When drawing a stretch image, do not use the CGImage property because it returns the base unstretched bitmap. Instead, use UIImage's drawing methods directly.

If you use an unusual context (outside of the UIView / CALayer drawing methods in the context of pure Core graphics), you may need to transfer the UIKit drawing to UIGraphicsPushContext() / UIGraphicsPopContext() calls.

+3
source

Source: https://habr.com/ru/post/1332304/


All Articles