CustomView *customView = [[CustomView alloc] init];
[self.window.contentView addSubview:customView];
当窗口调整大小时,如何customView.frame.size.height
始终等于contentView.frame.size.height
customView.frame.size.width = 20;
?
答案 0 :(得分:5)
设置自定义视图的 autoresizingMask :
CustomView *customView = [[CustomView alloc] init];
customView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[self.window.contentView addSubview:customView];
答案 1 :(得分:4)
Swift版本,应用autoresizingMask:
let customView = CustomView()
customView.autoresizingMask = [.width, .height]
self.window.contentView.addSubview(customView)
参考选项: https://developer.apple.com/documentation/appkit/nsview/autoresizingmask