NSWindow 에서 기본적으로 제공되는 타이틀바를 사용하고 싶지 않은 경우는
다음과 같이 상속을 받은 뒤 override 하고, 모양을 바꾸고 싶은 경우는
@interface PSWindow : NSWindow
// this point is used in dragging to mark the initial click location
@property (assign) NSPoint initialLocation;
@synthesize initialLocation;
/* In Interface Builder, the class for the window is set to this subclass. Overriding the initializer provides a mechanism for controlling how objects of this class are created. */
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)aStyle
backing:(NSBackingStoreType)bufferingType
// Using NSBorderlessWindowMask results in a window without a title bar.
self = [super initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered defer:NO];
// Start with no transparency for all drawing into the window
[self setAlphaValue:1.0];
// Turn off opacity so that the parts of the window that are not drawn into are transparent.
[self setMovableByWindowBackground:YES];
/* Custom windows that use the NSBorderlessWindowMask can't become key by default. Override this method so that controls in this window will be enabled. */
- (BOOL)canBecomeKeyWindow
/* Start tracking a potential drag operation here when the user first clicks the mouse, to establish the initial location. */
- (void)mouseDown:(NSEvent *)theEvent
// Get the mouse location in window coordinates.
self.initialLocation = [theEvent locationInWindow];
/* Once the user starts dragging the mouse, move the window with it. The window has no title bar for the user to drag (so we have to implement dragging ourselves) */
- (void)mouseDragged:(NSEvent *)theEvent
NSRect screenVisibleFrame = [[NSScreen mainScreen] visibleFrame];
NSRect windowFrame = [self frame];
NSPoint newOrigin = windowFrame.origin;
// Get the mouse location in window coordinates.
NSPoint currentLocation = [theEvent locationInWindow];
// Update the origin with the difference between the new mouse location and the old mouse location.
newOrigin.x += (currentLocation.x - initialLocation.x);
newOrigin.y += (currentLocation.y - initialLocation.y);
// Don't let window get dragged up under the menu bar
if ((newOrigin.y + windowFrame.size.height) > (screenVisibleFrame.origin.y + screenVisibleFrame.size.height)) {
newOrigin.y = screenVisibleFrame.origin.y + (screenVisibleFrame.size.height - windowFrame.size.height);
// Move the window to the new location
[self setFrameOrigin:newOrigin];
위 내용 중 드래그를 사용한 윈도우의 이동은 10.6 이상에서만 동작한다.