我可以向NSTextFieldCell中绘制的NSImage添加动作吗?(Can I add an action to a NSImage which is drawn in a NSTextFiel

编程入门 行业动态 更新时间:2024-10-26 08:25:26
我可以向NSTextFieldCell中绘制的NSImage添加动作吗?(Can I add an action to a NSImage which is drawn in a NSTextFieldCell?)

我可以向NSTextFieldCell中绘制的NSImage添加动作吗?

或者我应该为它实现NSImageView或NSButton? 如果是这样,我如何将这样的视图或按钮添加到NSTextFieldCell?

谢谢

Can I add an action to a NSImage which is drawn in a NSTextFieldCell ?

Or should I implement a NSImageView or NSButton for it ? If so, how do I add such view or button to the NSTextFieldCell ?

thanks

最满意答案

您可以使用NSButton而不是使用NSImage。设置NSImage的图像。添加该按钮的选择器。

NSButton *objNSButton = [[NSButton alloc] init]; [objNSButton setImage: YourImage]; [objNSButton setTarget:self]; [objNSButton setAction:@selector(buttonAction:)]; [objNSButton drawWithFrame:'SelfDefinedRectForButton' inView:NStextFieldCellObject];

如果在单击该按钮时想要图像中的chagne,也可以设置备用图像选项。

Instead of using NSImage,you can use NSButton .Set its image as you are doing for NSImage.Add the selector for that button .

NSButton *objNSButton = [[NSButton alloc] init]; [objNSButton setImage: YourImage]; [objNSButton setTarget:self]; [objNSButton setAction:@selector(buttonAction:)]; [objNSButton drawWithFrame:'SelfDefinedRectForButton' inView:NStextFieldCellObject];

You can also setAlternate image option if you want chagne in image on click of that button.

更多推荐

本文发布于:2023-07-26 02:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269908.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动作   NSImage   NSTextFieldCell   drawn   action

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!