0
所以我基本上试图列出可选文本项目(只是文本列表,没有按钮边框,背景等)。我想我可以用NSTableview做到这一点,但是试图让表格视图完全透明并且仍然有用,这就给了我一些问题。 Anwyays,我试图用编程方式创建NSButton,并将其添加到列表中的视图中,而没有任何背景或边框。但是,当我将属性设置为使按钮透明且没有边框时,该按钮的可点击区域将降级为单独按钮标题的文本。点击该按钮应该在其他地方(标题周围)不再有效。这是我正在使用的代码。我希望能够点击我创建按钮的矩形中的任何位置以引起点击。仅供参考我已经尝试过没有复选框图像的NSSwitchButton,它是同样的事情。谢谢你的帮助!NSButton的可选区域
for(NSString *theTask in theTasks){
NSButton *theCheckBox = [[[NSButton alloc] initWithFrame:NSMakeRect(xCoordinate + 25, yCoordinate + ([tasksWindow frame].size.height/2) - 60, [tasksWindow frame].size.width - 40, 25)] autorelease];
[theCheckBox setButtonType:NSToggleButton];
[theCheckBox setAction:@selector(taskChecked:)];
[[theCheckBox cell] setBackgroundColor:[NSColor clearColor]];
[[theCheckBox cell] setBordered:NO];
NSAttributedString *theTitle = [[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", theTask] attributes:[NSDictionary dictionaryWithObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName]] autorelease];
[theCheckBox setAttributedTitle:theTitle];
[[tasksWindow contentView] addSubview:theCheckBox];
yCoordinate -= 20;
}
更新:我已经能够确认,设置背景颜色明确的是什么似乎导致按钮停止其全境内响应点击(未去除边框)。