我正在研究iPad应用程序。在主屏幕上有6个在IB中创建的按钮。我想从代码动态安排它们,但我不能。 已经尝试设置对象的框架/中心,但它们没有移动。如何设置按钮位置?
我有一个数组,它包含按钮出口,并将它们排列在for循环中。 有什么建议吗?
谢谢!
编辑:
下面是一些代码(不是全部,但其余的现在是无关紧要的),通过按键我怎么循环。按钮插口已正确设置。按钮的标题更改正确,我也可以隐藏/显示按钮,但不是位置。
如果我只是尝试一些伪代码,如: tempBtn.frame = CGRectMake(100.0, 200.0, 60.0, 40.0);
没有变化(但我怀疑所有的6个按钮应该是在相同的位置)
// I have this array, which contains the button outlets
tAddBtnArray = [NSArray ArrayWithObjects:tAddBtn1,tAddBtn2,tAddBtn3,tAddBtn4,tAddBtn5,tAddBtn6, nil];
//I loop through the array, set button title, and trying to change the y position
for(int i=0;i<6;i++){
UIButton *tempBtn = [tAddBtnArray objectAtIndex:i];
[tempField setText:@"Set some title"];
}
你可以添加你使用的代码吗?您是否将插座映射到Interface Builder中的按钮? – hukir
是的,我用一些代码编辑了原始问题。正如我写的一样,一切看起来都很有效(可以在buttton上设置几乎所有的东西) – user1756687
你能告诉我这段代码在哪里运行吗?什么方法调用? – hukir