2009-06-29 46 views

回答

0

肯德尔,谢谢你的回答。

这里是我的解决方案:

if(previousFrame.origin.x + theStringSize.width > 220){ 
      roundedButton.frame = CGRectMake(15, previousFrame.origin.y + 30 , theStringSize.width + 8, theStringSize.height); 
      [myContainer insertSubview:roundedButton belowSubview:[tagsContainer.subviews lastObject]]; 
     }else { 
      roundedButton.frame = CGRectMake(previousFrame.origin.x + previousFrame.size.width + 5, previousFrame.origin.y, theStringSize.width + 5, theStringSize.height); 
      [myContainer insertSubview:roundedButton belowSubview:[tagsContainer.subviews lastObject]]; 
     } 

我算算,我已经多少像素从左侧移动。在某个阈值(在我的情况下是220),我开始一个新的行。

1

好像不是你做编程这些按钮,或您reiszed初始IB视图窗口要大,并预计其向下收缩到适合屏幕。

有问题的按钮无法放在屏幕上,因为它们是 - 您寻找什么效果?

如果你想让所有的按钮都适合你,你可以将文字大小设置得更小,然后他们可以适应。

如果你想按钮的大小,那么你将不得不做另一行,或将按钮放到侧滚动容器。

1

我一直在使用java,最近才开始学习Apple的Obj-C框架。

滚动和断行的替代方法是使用“1”行和“n”列的“网格”布局,其中n是按钮的数量。每个单元格都有固定的大小。你将不得不在你的超级视图的setNeedsLayout:方法中调整你的按钮(子视图)到任何你需要的宽度,使得所有的按钮都适合这一行。

请参阅java的GridLayout类。