Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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; ?

like image 497
user615816 Avatar asked Dec 01 '22 04:12

user615816


2 Answers

Swift version, to apply autoresizingMask:

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

ref to options

like image 71
pkis Avatar answered Dec 06 '22 19:12

pkis


Set the custom view's autoresizingMask:

CustomView *customView = [[CustomView alloc] init];
customView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[self.window.contentView addSubview:customView];
like image 26
trojanfoe Avatar answered Dec 06 '22 19:12

trojanfoe