macOS开发-知识点总结
2016-12-09 本文已影响101人
wright
- NSView的背景绘制为图片
NSImage *backgroundImage = [NSImage imageNamed:@"图片名称"];
backgroundImage.size = self.bounds.size;
[backgroundImage lockFocus];
NSColor* backgroundColor = [NSColor colorWithPatternImage:backgroundImage];
[backgroundColor set];
NSRectFill(self.bounds);
[backgroundImage unlockFocus];
// draw your new image
[backgroundImage drawInRect:self.bounds
fromRect:NSZeroRect // 绘制整张图片
operation:NSCompositeSourceOver
fraction:1.0f];
- 支持NSView的拖拽操作
-(NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender{
NSPasteboard *pboard = [sender draggingPasteboard];
if([[pboard types] containsObject:NSFilenamesPboardType])
{
return NSDragOperationCopy;
}
return NSDragOperationNone;
}
-(BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender
{
return YES;
}
-(BOOL)performDragOperation:(id<NSDraggingInfo>)sender
{
NSArray *filePaths =[[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
// 利用拖拽文件进行相应操作
}
-(void)concludeDragOperation:(id<NSDraggingInfo>)sender
{
//拖拽结束
}
- 判断NSWindow是否全屏
@interface NSWindow (WFFullScreen)
- (BOOL)isFullScreen;
@end
@implementation NSWindow (BFFullScreen)
- (BOOL)isFullScreen
{
return (([self styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask);
}
@end