Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想水平居中对齐父视图中的子视图(NSButton)。我想以编程方式执行此操作。
假设这myButton是一个NSButton *,那么:
myButton
NSButton *
- (void)setFrame:(NSRect)frameRect { [super setFrame:frameRect]; NSRect buttonRect = [myButton frame]; buttonRect.origin.x = (NSWidth(frameRect) / 2.0) - (NSWidth(buttonRect) / 2.0); [myButton setFrame:buttonRect]; }