user615816
user615816

Reputation: 449

NSView autoresize to fit the contentview

CustomView *customView = [[CustomView alloc] init];
[self.window.contentView addSubview:customView];

How can i make customView.frame.size.height always equals to contentView.frame.size.height when the window resize , and at the same time customView.frame.size.width = 20; ?

Upvotes: 6

Views: 8665

Answers (2)

pkis
pkis

Reputation: 6537

Swift version, to apply autoresizingMask:

let customView = CustomView()
customView.autoresizingMask = [.width, .height]
self.window.contentView.addSubview(customView)

ref to options

Upvotes: 12

trojanfoe
trojanfoe

Reputation: 122391

Set the custom view's autoresizingMask:

CustomView *customView = [[CustomView alloc] init];
customView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[self.window.contentView addSubview:customView];

Upvotes: 9

Related Questions