【发布时间】:2014-04-09 09:00:26
【问题描述】:
我是 iPhone 开发的新手。现在我想用水平滚动显示 40 个文本字段..
我已经使用下面的代码创建了这个UITextField。
// Create the scrollView:
UIScrollView *scrViewRankTracker = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, 320, 200)];
[scrViewRankTracker setContentSize: CGSizeMake(1200, 200)];
[self.view addSubview:scrViewRankTracker];
scrViewRankTracker.delegate = self;
CGRect frame = CGRectMake(10, 10, 80, 150);
[scrViewRankTracker scrollRectToVisible: frame animated:YES];
float x = 10;
float y = 10;
float width = 100;
float height = 30;
// Create the textfield using for loop:
for(int textFieldIndex =0;textFieldIndex<40;textFieldIndex++)
{
tfRankTracker = [[UITextField alloc]initWithFrame:CGRectMake(x, y, width, height)];
tfRankTracker.returnKeyType = UIReturnKeyDone;
[tfRankTracker setTag:textFieldIndex+1];
[tfRankTracker setBorderStyle:UITextBorderStyleRoundedRect];
[tfRankTracker setDelegate:self];
[scrViewRankTracker addSubview:tfRankTracker];
x = x + width + 20;
if((textFieldIndex+1)%10==0)
{
x = 10;
y = y + height + 20;
}
}
这段代码的输出将显示在下面 例如。
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
现在,假设如果我删除 4 号的文本字段,那么 14 号将取代 4 号……24 号将取代 14 号,34 号将取代 24 号...
谁能帮帮我!!!!!! 谢谢
【问题讨论】:
-
不要那样做......使用集合视图并将每个文本文件添加到集合视图中
-
有没有演示代码?
-
请从 cocoacontrols.com 找到集合视图并使用它。
标签: ios uiscrollview uitextfield