我試圖用50%不透明的黑色背景和白色文本創建自定義NSButton。要做到這一點,我子類NSButton和超載的drawRect:具有半透明背景的自定義NSButton
- (void) drawRect:(NSRect)dirtyRect
{
[self setBordered:NO];
//REMED since it has same effect as NSRectFill below
//[[self cell] setBackgroundColor:[NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:0.2]];
NSColor* backgroundColor = [NSColor colorWithCalibratedWhite:0 alpha:0.3f];
[backgroundColor setFill];
NSRectFill(dirtyRect);
[super drawRect:dirtyRect];
}
白色文本顯示正常,但按鈕的背景始終是100%不透明。 alpha值不被解釋。
任何想法?謝謝!
這工作!儘管我必須關閉Interface Builder中的按鈕上的Core Animation Layer。 – 2011-12-30 04:36:33