【问题标题】:Clipping within an UIView with some subviews在带有一些子视图的 UIView 中进行剪辑
【发布时间】:2009-06-29 16:22:42
【问题描述】:

我在 UIView 中有一些按钮。我的问题是,他们被砍了 在 UIView 的右侧关闭。如何防止这种情况发生?

alt text http://img.skitch.com/20090629-mj32p1bkff476256pwrpt69n2d.png

我已经检查过 Interface Builders 剪辑属性,但它不是 解决这个问题。

问候

【问题讨论】:

    标签: iphone cocoa-touch uiview uibutton


    【解决方案1】:

    您似乎以编程方式制作了这些按钮,或者您将初始 IB 视图窗口重新调整为更大,并希望它缩小以适合屏幕。

    相关按钮无法按原样显示在屏幕上 - 您在寻找什么效果?

    如果您希望所有按钮都适合,您可以将文本大小设置为更小,然后它们可以适合。

    如果您想要按钮的大小,那么您必须再制作一行,或者将按钮放入侧滚动容器中。

    【讨论】:

      【解决方案2】:

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

      滚动和换行的替代方法是使用具有 1 行和 n 列的“网格”布局,其中 n 是按钮的数量。每个单元格都有固定的大小。而且您必须将您的超级视图的 setNeedsLayout: 方法中的按钮(子视图)调整为您需要的任何宽度,以使所有按钮都适合该行。

      参见 java 的 GridLayout 类。

      【讨论】:

        【解决方案3】:

        肯德尔,感谢您的回答。

        这是我的解决方案:

            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)我开始新的一行。

        【讨论】:

          猜你喜欢
          • 2011-12-23
          • 2015-04-22
          • 2012-08-17
          • 2015-06-15
          • 1970-01-01
          • 2019-04-06
          • 2010-10-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多