0

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

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

4

1 回答 1

1

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

为此,您可以使用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 一起使用。

希望有帮助!

于 2012-07-29T19:50:22.890 回答