简体   繁体   English

iOS-更改Interface Builder中视图的大小以放入scrollview

[英]iOS - Change size of view in Interface Builder for putting into scrollview

Here is my problem: 这是我的问题:

I want to create a view whose height exceeds the height of the iPhone-screen. 我想创建一个高度超过iPhone屏幕高度的视图。 To deal with that, I am using a UIScrollView which works just fine. 为了解决这个问题,我正在使用一个UIScrollView,它工作得很好。 I created the scroll view in interface builder and set the content size programmatically to twice the height of the screen (that's enough for my purpose). 我在界面构建器中创建了滚动视图,并以编程方式将内容大小设置为屏幕高度的两倍(这足以满足我的目的)。 I can run the code and it works just fine. 我可以运行代码,并且效果很好。 I can scroll up an down without trouble. 我可以毫无困难地向上滚动。

The only thing I don't get is how I can add more items (buttons, labels etc.) to the view in interface builder, since it doesn't allow me to change the size of the view. 我唯一不了解的是如何在界面构建器中向视图添加更多项(按钮,标签等),因为它不允许我更改视图的大小。 I was thinking to create a scroll view as a top level object and then place a view (the contentview) of a larger height into it. 我正在考虑将滚动视图创建为顶级对象,然后将更大高度的视图(contentview)放入其中。 Now the only thing to do is add all the items to the contentview, which is not possible because in interface builder the contentview has only its regular size. 现在唯一要做的就是将所有项目添加到contentview中,这是不可能的,因为在界面生成器中,contentview仅具有常规大小。

I am thankful for any thoughts on this :-) 我对此表示感谢:-)

You can change the size of your UIView from the interface builder. 您可以从界面构建器更改UIView的大小。

For that you have to go to Interface Builder of particular UIView. 为此,您必须转到特定UIView的Interface Builder。 From Simulated Metrics * select Size = Freeform * and now you are able to change the size of UIView from interface builder. 从“ 模拟指标” * 选择“大小=自由格式” *,现在您可以从界面生成器中更改UIView的大小。

The accepted answer is accurate but no longer complete for iOS7 and XCode5. 可接受的答案是准确的,但对于iOS7和XCode5而言不再完整。 Check out @Whasssaaahhh answer here for more detail. 在这里查看@Whasssaaahhh 答案以获取更多详细信息。

You can drag items on top of the view in two ways. 您可以通过两种方式在视图顶部拖动项目。

1) Change Y-Position: If you select your UIView and in Size Inspector change its Y position to whatever section of the view you want to see (try something like -100 to go down or 100 to go up, play around with whatever numbers work for your screen size) you can drag all your buttons, labels, text fields however you like for each visible section. 1)更改Y位置:如果选择UIView,然后在Size Inspector中将其Y位置更改为要查看的视图的任何部分(尝试将-100向下或100向上移动,请按任意数字播放以适合您的屏幕尺寸),但是您可以根据需要为所有可见部分拖动所有按钮,标签,文本字段。

2) Drag With Mouse: If you carefully select just the UIView with your mouse and carefully drag it either upwards or downwards and let go, it will snap to the new position so you can edit it. 2)用鼠标拖动:如果您用鼠标仔细选择UIView,然后小心地向上或向下拖动它,然后放开,它将锁定到新位置,以便您可以对其进行编辑。 It's easier to "see" this if you drag some objects on it first. 如果首先在其上拖动一些对象,则更容易“看到”该图像。

You can change the size of your view and size of your scrollview along with the addition of objects. 您可以更改视图的大小和滚动视图的大小,以及添加对象。 add the added object height to the scrollView.contentSize and also add into the height of the view. 将添加的对象高度添加到scrollView.contentSize,还添加到视图的高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ScrollView在Interface Builder中无法正确调整大小 - ScrollView won't size correctly in Interface Builder 界面生成器中的iOS阴影视图 - iOS shadow view in interface builder xcode 4.5,视图大小在界面构建器中不可编辑 - xcode 4.5, view size not editable in interface builder 无法在Interface Builder中更改TableView的大小 - Can't change the size of a TableView in Interface Builder iOS在界面生成器中使用继承的View - IOS use inherited View inside interface builder 我在界面生成器中创建UIImage视图,如何在代码中更改其框架(位置和大小)? - I create an UIImage view in interface builder, how to change its frame (position&size) in code? 在ios7,界面生成器中更改checkMark颜色 - Change checkMark color in ios7, Interface Builder 如何在方向更改时加载新视图-iOS SDK Xcode Interface Builder - How to load a new view upon orientation change - iOS SDK xcode Interface builder XCode6,iOS8如何滚动启用尺寸类的视图控制器以查看界面生成器中的屏幕外元素? - XCode6, iOS8 how to scroll a size class enabled view controller to see offscreen elements within interface builder? 有没有办法在没有界面生成器的情况下使用iOS大小类(以编程方式)? - Is there a way to use iOS Size Classes without interface builder(programatically)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM