NSButton没有锁定

时间:2013-08-16 01:40:18

标签: objective-c macos cocoa osx-mountain-lion nsbutton

我正在尝试以编程方式制作NSView而且我有点卡住了。我通常不做GUI编程,这是我第一次尝试创建视图。一切都很好,直到我尝试调整窗口大小。按钮不会保持“固定”在该位置。它在视图中不断移动。我的代码如下:

-(void) awakeFromNib
{
NSView *test=[[NSView alloc] initWithFrame:windowRect];
button=[[NSButton alloc]initWithFrame:NSMakeRect(window.frame.origin.x-10.0, 
window.frame.origin.y+50.0, 80.0, 50.0)];
[button setBezelStyle:NSRoundedBezelStyle];
window.title=@"window Test";
[button setTitle:@"click me"];
[button needsDisplay];
[test addSubview:button];
[[window contentView] addSubview:test];
[window makeKeyAndOrderFront:nil];
[[window contentView] setAutoresizesSubviews:YES];
}

按钮对象只是常规NSButton

0 个答案:

没有答案