你可以这样做:
-(voID)awakeFromNib { //Start from bottom left corner int x = 100; //possition x int y = 100; //possition y int wIDth = 130; int height = 40; NSbutton *mybutton = [[[NSbutton alloc] initWithFrame:NSMakeRect(x,y,wIDth,height)] autorelease]; [[windowOutlet contentVIEw] addSubvIEw: mybutton]; [mybutton setTitle: @"button Title!"]; [mybutton setbuttonType:NSMomentarylightbutton]; //Set what type button You want [mybutton setBezelStyle:NSRoundedBezelStyle]; //Set what style You want [mybutton setTarget:self]; [mybutton setAction:@selector(buttonpressed)];}-(voID)buttonpressed { NSLog(@"button pressed!"); //Do what You want here... }
** WindowOutlet是窗口,所以不要忘记IBOutlet它.
总结以上是内存溢出为你收集整理的objective-c – 以编程方式在OS X应用程序中创建和定位NSButton?全部内容,希望文章能够帮你解决objective-c – 以编程方式在OS X应用程序中创建和定位NSButton?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)