残念ながら、すべてのNSViewのサブクラスのためにこれを行うための標準的な方法はありません。あなたは、多くの場合、これを使用して自分自身を見つける場合は、次のように、あなたがNSBox
にカテゴリを作成することができ
NSRect availableRect = [someNSBox bounds];
NSSize boxMargins = [someBox contentViewMargins];
availableRect = NSInsetRect(availableRect, boxMargins.width, boxMargins.height);
:次のようにあなたの具体的な例では、NSBox
内の位置と子ビューのサイズを計算することができる
// MyNSBoxCategories.h
@interface NSBox (MyCategories)
- (NSRect)contentFrame;
@end
// MyNSBoxCategories.m
@implementation NSBox (MyCategories)
- (NSRect)contentFrame
{
NSRect frameRect = [self bounds];
NSSize margins = [self contentViewMargins];
return NSInsetRect(frameRect, margins.width, margins.height);
}
@end
そして、あなたはそうのようにそれを使用します。
#import "MyNSBoxCategories.h"
//...
NSRect frameRect = [someNSBox contentFrame];
[myContentView setFrame:frameRect];
[someNSBox addSubview:myContentView];
ご返信ありがとうございます。私は別の例を使用していたはずですが、NSBoxは他の多くのクラスに欠けているこれらの余分なメソッドを持っているという点で多少特別です:( –
問題ありません。 –