gpt4 book ai didi

objective-c - 我该如何修改以及修改什么类/文件才能以编程方式插入 Cocoa NSButton?

转载 作者:行者123 更新时间:2023-12-03 17:59:30 25 4
gpt4 key购买 nike

如何以及修改哪些类/文件才能以编程方式插入 avCocoa NSButton? (适用于 Mac,不适用于 iPhone)

我尝试了以下方法,但不起作用:(请求成员“查看”非结构或联合的内容。)

- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
NSButton *btn = [NSButton alloc];
[self.view addSubview:btn];
}

最佳答案

您必须将其添加到窗口的内容 View 中。

- (void)windowControllerDidLoadNib:(NSWindowController *)aController {
[super windowControllerDidLoadNib:aController];

// Get our content view.
NSView *contentView = aController.window.contentView;

// Create the rectangle in which to place the button.
NSRect buttonFrame = NSMakeRect(0, 0, 100, 25);
buttonFrame.origin.x = round((contentView.frame.size.width-buttonFrame.size.width)/2);
buttonFrame.origin.y = round((contentView.frame.size.height buttonFrame.size.height)/2);

// Create and add the button.
NSButton *button = [[[NSButton alloc] initWithFrame:buttonFrame] autorelease];
[button setBezelStyle:NSRoundedBezelStyle];
[contentView addSubview:button];
}

关于objective-c - 我该如何修改以及修改什么类/文件才能以编程方式插入 Cocoa NSButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8569225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com