ResizableImageWithCapInsets for NSImage?

In UIKitwe have - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets.

Is there something similar in AppKitto making tileable NSImage?

+5
source share
3 answers

Nope. NSImage does not contain such skills. You will have to cut, resize and assemble the image first.

You can examine the subclass of NSCustomImageRep that implements this, and then you could use the same method to implement the OS X version.

+4
source

Instead, you can use [NSImage drawAtPoint], for example:

@implementation NSImage (CapInsets)

- (void)drawImageWithLeftCapWidth:(NSInteger)left topCapHeight:(NSInteger)top destRect:(NSRect)dstRect
{
    NSSize imgSize = self.size;
    [self drawAtPoint:dstRect.origin fromRect:NSMakeRect(0, 0, left, top) operation:NSCompositeSourceOver fraction:1];
    [self drawInRect:NSMakeRect(left, 0, dstRect.size.width-2*left, top) fromRect:NSMakeRect(left, 0, imgSize.width-2*left, top) operation:NSCompositeSourceOver fraction:1];
    [self drawAtPoint:NSMakePoint(dstRect.origin.x+dstRect.size.width-left, dstRect.origin.y) fromRect:NSMakeRect(imgSize.width-left, 0, left, top) operation:NSCompositeSourceOver fraction:1]; 
}

@end
+4
source

NSImage 10.10 (Yosemite). NSImage :

@property NSEdgeInsets capInsets

, iOS. [image drawInRect:rect], . , , 10.10 ; .

+2

All Articles