繁体   English   中英

iOS:子视图的xcode实例

[英]iOS: xcode instance of a subview

我有一个带有按钮和8个标签的视图,我想通过用户输入来重复此视图以自定义这些标签,因此该基本视图将在屏幕上多次显示,并且我不希望它们掩盖彼此之间,按钮和标签的位置在每个视图中都相同。

在用户输入实例视图之后,如何以编程方式使新视图出现,并确保它不会掩盖任何其他视图,我希望这不会太宽泛,我只想使用一个带有按钮的设置视图,然后8个标签,可多次复制并显示用户输入,谢谢。

如果我了解您要查找的内容,则希望显示屏向上滚动,显示用户已创建的所有不同视图,一个接一个。

为此,可以使用UIScrollView并根据需要以编程方式将视图添加到滚动视图。 确保增加滚动视图的contentSize以解决添加的视图。

这是一些代码:

UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

//create and add as many of yourView as necessary for your project - y would be the the offset so it gets displayed under the other views

YourCustomView *yourCustomView = [[YourCustomView alloc] initWithFrame:CGRectMake(0, y,self.view.frame.size.width, self .view.frame.size.height)]; 

//populate yourCustomView with the appropriate information...

[scrollview addSubview:yourCustomView];

//when you are done adding your views - w and h are whatever your content dictates they are
scrollview.contentSize = CGSizeMake(w, h);   
[self.view addSubview:scrollview];

另外,根据您的设置和设计,您可以将UITableView与显示相关信息的自定义UITableViewCell一起使用。

希望有帮助!

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM