Objective c 以编程方式创建Cocoa单选按钮
我需要用编程的方式制作一个可可单选按钮,有人能解释一下怎么做或者怎么做好吗?摘自 单选按钮实际上是按钮单元的矩阵。独家 选择性是基质的一种性质 要以编程方式创建按钮单元格矩阵,您可以执行完全相同的操作 IB根据您的输入以编程方式执行的操作。例如 创建NSMatrix实例,将其单元原型设置为NSButtonCell,设置 矩阵的属性通过其公共方法(相同的方法) 使用),并设置原型按钮单元格和/或所有 包含按钮单元 有关如何以编程方式制作NSMatrix的更多示例代码,请参见 单选按钮实际上是按钮单元的矩阵。独家 选择性是基质的一种性质 要以编程方式创建按钮单元格矩阵,您可以执行完全相同的操作 IB根据您的输入以编程方式执行的操作。例如 创建NSMatrix实例,将其单元原型设置为NSButtonCell,设置 矩阵的属性通过其公共方法(相同的方法) 使用),并设置原型按钮单元格和/或所有 包含按钮单元 有关如何以编程方式制作NSMatrix的更多示例代码,请参见。 按钮编程主题,特别是单选按钮(带有示例代码) 按钮编程主题,特别是单选按钮(带有示例代码)Objective c 以编程方式创建Cocoa单选按钮,objective-c,cocoa,radio-button,Objective C,Cocoa,Radio Button,我需要用编程的方式制作一个可可单选按钮,有人能解释一下怎么做或者怎么做好吗?摘自 单选按钮实际上是按钮单元的矩阵。独家 选择性是基质的一种性质 要以编程方式创建按钮单元格矩阵,您可以执行完全相同的操作 IB根据您的输入以编程方式执行的操作。例如 创建NSMatrix实例,将其单元原型设置为NSButtonCell,设置 矩阵的属性通过其公共方法(相同的方法) 使用),并设置原型按钮单元格和/或所有 包含按钮单元 有关如何以编程方式制作NSMatrix的更多示例代码,请参见 单选按钮实际上是按钮单
以下是一个以编程方式创建单选按钮的示例代码:
//create the radio button prototype
NSButtonCell *proto = [[NSButtonCell alloc] init];
[proto setTitle:@"Options"];
[proto setButtonType: NSRadioButton];
//define the matrix size where you'll put the radio buttons
NSRect matrixRect = NSMakeRect(20.0,20.0,125.0,125.0);
//define the matrix specifying that it will contain radio buttons of
//prototype "proto" defined above, and that it will have 3 radio buttons
//arranged on 1 column
NSMatrix *matrix = [[NSMatrix alloc] initWithRect: matrixRect
mode: NSRadioModeMatrix
prototype: (NSCell *)proto
numberOfRows:3 numberOfColumns:1];
//this assumes that you connected the window object to an outlet
[[windowOutlet contentView] addSubview: matrix];
//set the radio buttons' titles by getting references to the matrix's cells
NSArray *cells = [matrix cells];
[[cells objectAtIndex:0] setTitle:@"Option 1"];
[[cells objectAtIndex:1] setTitle:@"Option 2"];
[[cells objectAtIndex:2] setTitle:@"Option 3"];
[proto release];
[matrix release];
玩得开心!是的,这是从中提取的,但是我添加了一些个人注释来解释这个过程。下面是一个以编程方式创建单选按钮的示例代码:
//create the radio button prototype
NSButtonCell *proto = [[NSButtonCell alloc] init];
[proto setTitle:@"Options"];
[proto setButtonType: NSRadioButton];
//define the matrix size where you'll put the radio buttons
NSRect matrixRect = NSMakeRect(20.0,20.0,125.0,125.0);
//define the matrix specifying that it will contain radio buttons of
//prototype "proto" defined above, and that it will have 3 radio buttons
//arranged on 1 column
NSMatrix *matrix = [[NSMatrix alloc] initWithRect: matrixRect
mode: NSRadioModeMatrix
prototype: (NSCell *)proto
numberOfRows:3 numberOfColumns:1];
//this assumes that you connected the window object to an outlet
[[windowOutlet contentView] addSubview: matrix];
//set the radio buttons' titles by getting references to the matrix's cells
NSArray *cells = [matrix cells];
[[cells objectAtIndex:0] setTitle:@"Option 1"];
[[cells objectAtIndex:1] setTitle:@"Option 2"];
[[cells objectAtIndex:2] setTitle:@"Option 3"];
[proto release];
[matrix release];
玩得开心!是的,这是从中摘录的,但是我添加了一些个人评论来解释这个过程。非常好,谢谢。为什么这段代码没有出现在《矩阵编程指南》中?非常好,谢谢。为什么这段代码不在《矩阵编程指南》中?