0

我正在开发一个目标 C 项目,以及另一个 Java 项目。我问我一个问题,因为我知道如何在 Java 中进行多重声明,如下所示:

for (int l = 7; l>0; l--)
    {
        for (int g = 1; g<8; g++)
        {
            ButtonTest = new JButton();
            ButtonTest.setBorderPainted(false);
            ButtonTest.setOpaque(true);
            ButtonTest.setName("Bouton"+l+g);
            ButtonTest.addActionListener(this);
            PanelTest.add(ButtonTest);
        }
    }

我如何在目标 C 中制作这种代码,例如 UIButtons?

非常感谢 !

4

1 回答 1

2

它与Java中的几乎相同:

for (int l = 7; l>0; l--)
{
    for (int g = 1; g<8; g++)
    {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y, width, height)];
        // Do any other configuration here.
        [button setTitle:@"foo" forState:UIControlStateNormal];
        [myView addSubview:button];
    }
}

这将生成 UIButtons 并将它们添加到视图中。不过,您可能必须自己生成坐标和大小,我不知道这在 Java 中是否有所不同。

于 2013-05-24T21:48:39.677 回答