思路如下:
1.在主窗口中重寫awakeFromNib
- (void) awakeFromNib{
[self setOpaque:NO];
[selfsetBackgroundColor:[NSColorclearColor]];
}
只要實現了該步驟,那麼主窗口將會實現透明顯示
2.在主窗口的主view的drawRect中重繪所要貼圖的內容,這個就很自由了,隨便給上自己測試的:
- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
//NSRectFillUsingOperation(dirtyRect, NSCompositeClear);
CGContextRef context = [[NSGraphicsContextcurrentContext]graphicsPort];
//CGContextSetRGBFillColor(context, 0.5, 0.5, 0.5, 0.9);//0.0, 0, 0.5, 0.1);
//CGContextFillPath(context);
int x = 0, y =0;
CGImageRef ri = GetCGImageNamed([[[NSBundlemainBundle] resourcePath]stringByAppendingString:@"/frame.png"]);
float w =CGImageGetWidth(ri), h = CGImageGetHeight(ri);
NSRect rect = [selfbounds];
while (YES) {
CGContextDrawImage(context, CGRectMake(x, y, w, h), ri);
x += w;
if (x >= rect.size.width) {
y += h;
x =0;
}
if (y >= rect.size.height) {
break;
}
}
[NSGraphicsContextrestoreGraphicsState];
}