2011-08-05 15 views
0

コーナーを丸くしたいカスタムのNSViewサブクラスがあります。私は、.mファイルに次のコードを使用します。NSViewサブクラスの丸みのあるコーナーは機能しません

#import "ItemImageSelectionView.h" 

@implementation ItemImageSelectionView 

- (id)initWithFrame:(NSRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     self.wantsLayer = YES; 
     self.layer.frame = self.frame; 
    } 

    return self; 
} 

- (void)drawRect:(NSRect)dirtyRect 
{ 

    [[NSColor colorWithCalibratedRed:0.0 green:0.5 blue:1 alpha:1] set]; 
    NSRectFill(dirtyRect); 

    [self.layer setCornerRadius:5.0]; 

} 

@end 

私はビュー、かなりデフォルト初期化する場合は、このコードを使用します。

NSView *imageSelectionView = [[ItemImageSelectionView alloc] initWithFrame:CGRectMake(imageView.frame.origin.x - 2, imageView.frame.origin.y - 2, imageView.frame.size.width + 4, imageView.frame.size.height + 4)]; 
    [self addSubview:imageSelectionView positioned:NSWindowBelow relativeTo:imageView]; 

をしかし、それはすべての丸みを帯びた角を設定していません!私は間違って何をしていますか?

答えて

1

drawrect法では、角を丸める必要はありません。それをinitで設定します。また、オーバーライドされたメソッドでsuperメソッド[super drawRect:dirtyRect]を呼び出す必要があります。あなたの塗りつぶしのカスタムがどのようにレイヤーとやりとりするかはわかりません。 [self.layer setMasksToBounds:YES]を設定する必要があります。

関連する問題