我尝试为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,我不知道我怎么能推它。
答案 0 :(得分:0)
Stretchable-NSImage没有改变图像,但改写了drawRect