我可以向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.
更多推荐
发布评论