思路如下:
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];
}