我尝试为 mac 做 resizableImageWithCapInsets (如在 iOS 中)。
// right bubble
NSLog(@"==================== OLD VALUES ==============");
NSLog(@"size->%@",NSStringFromSize(size));
NSLog(@"cellView.frame->%@",NSStringFromRect(cellView.frame));
NSLog(@"message.frame->%@",NSStringFromRect(cellView.message.frame));
NSLog(@"background.frame->%@",NSStringFromRect(cellView.background.frame));
cellView.background.frame = CGRectMake(cellView.frame.size.width - size.width,
- size.height + cellView.date.frame.size.height * 1.8, size.width, size.height);
necessaryBackgroundImage = [[NSImage imageNamed:@"OutgoingMessageBuble.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:15];
cellView.message.frame = CGRectMake(cellView.frame.size.width - size.width,
- size.height + cellView.date.frame.size.height * 1.8, size.width, size.height);
NSLog(@"==================== NEW VALUES ==============");
NSLog(@"message.frame->%@",NSStringFromRect(cellView.message.frame));
NSLog(@"background.frame->%@",NSStringFromRect(cellView.background.frame));
NSLog(@"necessaryBackgroundImage.size->%@",NSStringFromSize(necessaryBackgroundImage.size));
cellView.background.image = necessaryBackgroundImage;
我确实从这里尝试 NSImage 子类: https ://github.com/beefon/Mac---Stretchable-NSImage/blob/master/README
但这不是成功:
一个类总是返回错误大小的图像:
> 2012-11-22 01:02:30.009[37363:303] necessaryBackgroundImage.size->{43,
> 32} 2012-11-22 01:02:30.004[37363:303]
> necessaryBackgroundImage.size->{43, 32}
我希望图像大小为必要的框架:
> 2012-11-22 01:02:30.003[37363:303] background.frame->{{50.6875,
> -115.19999999999999}, {265.3125, 162}}
请你能解释一下,我错在哪里?代码片段赞赏,我明白,我必须使用 NSDrawNinePartImage,但更好的是避免很长的路要走。我还发现,子类 NSImage 的 drawInRect 没有在任何地方调用,我不知道如何推送它。