改变NSButton CALayer隐藏其标题

时间:2014-06-18 14:21:06

标签: ios calayer nsbutton

我正试图通过这种方式更改按钮背景:

    [table[i][j] setAttributedTitle:attrString];
    [table[i][j] setTitle:@"-"];
    table[i][j].tag=i*10+j;
    table[i][j].frame = CGRectMake((i*30+40), (j*30+106), 30.0, 30.0);
    [self.mainView addSubview:table[i][j]];
    CALayer *buttonLayer = [CALayer layer];
    buttonLayer.contents=(id)[NSImage imageNamed:@"icaseinactiv"];
    [table[i][j] setWantsLayer:YES]; // view's backing store is using a Core Animation Layer
    [table[i][j] setLayer:buttonLayer];

但是,一旦我应用了新图层,它的标题就会消失(当我删除最后一行时标题仍然存在。我做错了什么?

提前致谢

1 个答案:

答案 0 :(得分:0)

我很确定NSButton默认情况下不会使用图层,所以它将使用普通的[NSView drawRect:]方法进行绘制。然后你添加了一个覆盖这个画布的图层,然后就会发生这种情况。

为了做你想做的事,你需要继承NSButtonCell我认为。

相关问题