2
指南針的每個點我的圈子的外邊緣被裁剪(大概是由矩形框架)。我如何讓圓圈在框架內顯示? (這正從一個按鈕,點擊創建):可可NSView:製作圈子,但他們正在裁剪
在我AppController.m
#import "AppController.h"
#import "MakeCircle.h"
@implementation AppController
- (IBAction)makeCircle:(id)sender {
MakeCircle* newCircle = [[MakeCircle alloc] initWithFrame:NSMakeRect(100.0, 100.0, 30.0, 30.0)];
[[[[NSApplication sharedApplication] mainWindow] contentView] addSubview:newCircle];
[newCircle release];
}
@end
在我MakeCircle.m
- (void)drawRect:(NSRect)rect {
[self setNeedsDisplay:YES];
[[NSColor blackColor] setStroke];
// Create our circle path
NSBezierPath* circlePath = [NSBezierPath bezierPath];
[circlePath appendBezierPathWithOvalInRect: rect];
//give the line some thickness
[circlePath setLineWidth:4];
// Outline and fill the path
[circlePath stroke];
}
感謝。
`NSInsetRect`將通過3線縮短了代碼。 – Richard 2011-02-09 15:46:04