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

我怎样才能使窗口调整大小时customView.frame.size.height总是等于contentView.frame.size.height,同时customView.frame.size.width = 20;

4

2 回答 2

11

Swift 版本,应用 autoresizingMask:

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

参考选项

于 2017-07-26T10:59:05.763 回答
9

设置自定义视图的autoresizingMask

CustomView *customView = [[CustomView alloc] init];
customView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[self.window.contentView addSubview:customView];
于 2012-12-06T11:50:32.203 回答