Window 上的三个按钮
NSButton *closeBtn = [self standardWindowButton:NSWindowCloseButton];
NSButton *miniaturizeBtn = [self standardWindowButton:NSWindowMiniaturizeButton];
NSButton *zoomBtn = [self standardWindowButton:NSWindowZoomButton];
创建时 frame 分别为
(7.000000,3.000000),(14.000000,16.000000)
(27.000000,3.000000),(14.000000,16.000000)
(47.000000,3.000000),(14.000000,16.000000)
button 创建时是自动布局,直接修改 frame 无效
关闭自动布局,添加约束布局就能修改 window button 的位置
closeBtn.translatesAutoresizingMaskIntoConstraints = NO;
miniaturizeBtn.translatesAutoresizingMaskIntoConstraints = NO;
zoomBtn.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *leftContraint1 = [NSLayoutConstraint constraintWithItem:closeBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:closeBtn.superview attribute:NSLayoutAttributeLeft multiplier:1.0 constant:4.0];
NSLayoutConstraint *topContraint1 = [NSLayoutConstraint constraintWithItem:closeBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:closeBtn.superview attribute:NSLayoutAttributeTop multiplier:1.0 constant:3.0];
leftContraint1.active = YES;
topContraint1.active = YES;
NSLayoutConstraint *leftContraint2 = [NSLayoutConstraint constraintWithItem:miniaturizeBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:miniaturizeBtn.superview attribute:NSLayoutAttributeLeft multiplier:1.0 constant:23.0];
NSLayoutConstraint *topContraint2 = [NSLayoutConstraint constraintWithItem:miniaturizeBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:miniaturizeBtn.superview attribute:NSLayoutAttributeTop multiplier:1.0 constant:3.0];
leftContraint2.active = YES;
topContraint2.active = YES;
NSLayoutConstraint *leftContraint3 = [NSLayoutConstraint constraintWithItem:zoomBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:zoomBtn.superview attribute:NSLayoutAttributeLeft multiplier:1.0 constant:43.0];
NSLayoutConstraint *topContraint3 = [NSLayoutConstraint constraintWithItem:zoomBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:zoomBtn.superview attribute:NSLayoutAttributeTop multiplier:1.0 constant:3.0];
leftContraint3.active = YES;
topContraint3.active = YES;