Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stretch PNGs smoothly in Cocoa AppKit

In questions like this one it shows how to use UIKit's

-(UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

to stretch a PNG easily, e.g when inserting text in an iChat like bubble. I would like to do the same on regular AppKit/Cocoa/desktop app using CoreGraphics or some NSImage related API but couldn't find an equivalent method. Does anybody know how to do this in AppKit?

like image 646
John Wright Avatar asked Dec 23 '22 07:12

John Wright


2 Answers

Use NSDrawThreePartImage or NSDrawNinePartImage.

like image 126
Peter Hosey Avatar answered Jan 04 '23 23:01

Peter Hosey


Just use -[NSImage drawInRect:fromRect:operation:fraction:], and pass NSZeroRect as the fromRect; parameter.

like image 21
Ben Gottlieb Avatar answered Jan 05 '23 01:01

Ben Gottlieb