コンパスの各ポイントのサークルの外側のエッジが(おそらくrectフレームによって)切り取られています。フレーム内に円を表示するにはどうすればよいですか? (これは、ボタンのクリックから作成されたばかり):私のAppController.mでCocoa NSView:サークルを作成していますが、クロップしています
#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
ありがとう、私は同じことを考え出しました。 - ココアにストロークを描画する方法/プロパティはありません。 - そしてNSAppのヒントのおかげで... – PruitIgoe
私はこれらの2つの行を変更しました:rectangle.size.width - = STROKE_WIDTH/2; rectangle.size.height - = STROKE_WIDTH/2; 〜rectangle.size.width - = STROKE_WIDTH; rectangle.size.height - = STROKE_WIDTH; – PruitIgoe