objective-c – NSOutlineView更改公开图像

objective-c – NSOutlineView更改公开图像,第1张

概述我的大纲视图,我正在添加自定义单元格,绘制自定义单元格,我指的是示例代码,存在于 Cocoa文档中 http://www.martinkahr.com/2007/05/04/nscell-image-and-text-sample/ 我想用我的自定义图像更改单元格的显示图像,我尝试过以下 *** 作 - (void)outlineView:(NSOutlineView *)outlineView will 我的大纲视图,我正在添加自定义单元格,绘制自定义单元格,我指的是示例代码,存在于 Cocoa文档中

http://www.martinkahr.com/2007/05/04/nscell-image-and-text-sample/

我想用我的自定义图像更改单元格的显示图像,我尝试过以下 *** 作

- (voID)outlineVIEw:(NSOutlineVIEw *)outlineVIEw willdisplayCell:(ID)cell fortableColumn:(NStableColumn *)tableColumn item:(ID)item     {        if([item isKindOfClass:[NSValue class]])        {            MyData *pDt = (MyData *)[item pointerValue];            if(pDt->isGroupElement())            {                [cell setimage:pGroupImage];            }        }}

但那也没有用,有没有其他方法来改变披露形象,
另外我怎么能在willdisplayCell中找到Item是展开还是折叠,所以我可以相应地设置图像,

这只是改变披露形象的地方吗?

解决方法 你有基本的想法,但你需要做的是自己绘制图像.这是我使用的代码:

- (voID)outlineVIEw:(NSOutlineVIEw *)outlineVIEw willdisplayOutlineCell:(ID)cell fortableColumn:(NStableColumn *)tableColumn item:(ID)item {    Nsstring *theImagename;    NSInteger theCellValue = [cell integerValue];    if (theCellValue==1) {        theImagename = @"PMOutlineCellOn";    } else if (theCellValue==0) {        theImagename = @"PMOutlineCellOff";    } else {        theImagename = @"PMOutlineCellMixed";    }    NSImage *theImage = [NSImage imagenamed: theImagename];    NSRect theFrame = [outlineVIEw frameOfOutlineCellAtRow:[outlineVIEw rowForItem: item]];    theFrame.origin.y = theFrame.origin.y +17;    // adjust theFrame here to position your image    [theImage compositetoPoint: theFrame.origin operation:NSCompositeSourceOver];    [cell setimageposition: NSNoImage];}

您将需要3个不同的图像,一个用于ON状态,一个用于OFF状态,另一个用于MIXED状态,应该在两者之间.混合状态确保您仍然可以获得开始和结束动画.

总结

以上是内存溢出为你收集整理的objective-c – NSOutlineView更改公开图像全部内容,希望文章能够帮你解决objective-c – NSOutlineView更改公开图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1070470.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存