【问题标题】:resizableImageWithCapInsets inside NSTableView (view based)NSTableView 内的 resizableImageWithCapInsets(基于视图)
【发布时间】:2012-11-21 23:12:33
【问题描述】:

我尝试为 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}}

请你解释一下,我错在哪里?代码 sn-p 赞赏,我明白,我必须使用 NSDrawNinePartImage,但最好避免走很长的路。我还发现,子类 NSImage 的 drawInRect 没有在任何地方调用,我不知道如何推送它。

【问题讨论】:

  • 你能找到解决这个问题的方法吗?
  • 暂时不记得了,但一切正常)

标签: objective-c cocoa nstableview nstablecellview


【解决方案1】:

Stretchable-NSImage 并没有改变图片,而是重写了drawRect

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 2013-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多