プログラムで UIView に UITextView を追加しました。追加されたテキストビューは編集できません。データを表示するだけです。テキストビューに表示されるデータは、配列から取得されます。テキストビューの数は、配列に保存したテキストと同じです。テキストビューは、最初から最後まで1つずつ表示されます。まず、テキストビューの位置を1つずつ設定する必要がありますテキストビューが来て、ある位置に設定され、2番目は最初のテキストビューの直前に設定され、3番目は2番目の直前に設定されます.. 注: Animationを使用するようなもの。1つのテキストビューが上から来て、250のY位置で停止し、次のテキストビューであるとしますYポジションの250までは来ません。等々。これを行う方法がわかりません。アイデアを教えてください。
4 に答える
配列とデータを考慮しないでくださいUITextView
....一時的なものです..
NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:@"One",@"Two",@"three",@"Four",@"Five",@"Six",@"Seven",@"Eight",@"Nine",@"Ten", nil];
for(int i=0;i<[array count];i++) {
UITextView *textView = [[UITextView alloc]init];
[textView setFrame:CGRectMake(20, 20*i+height, 200, height)];
[textView setBackgroundColor:[UIColor redColor]];
[textView setText:[array objectAtIndex:i]];
[self.view addSubview:textView];
}
配列に基づいてビューにプログラムでテキストビューを追加したい場合、ビューにテキストビューを追加している場合、問題があります(テキストビューの数が多い場合は、スクロールビューを取得する必要があります)。これが、スクロールビューを取得する方が良い理由ですスクロールビューをビューに追加してから、テキストビューをスクロールビューに追加します。
now take constant x-coordinate value ,width and height only change y-coordinate value and you must give the content size to scrollview .
for(int i=1;i<[array length];i++){
text_desc = [[UITextView alloc] initWithFrame:CGRectMake(63,64*i,370,60)];
text_desc.font = [UIFont fontWithName:@"Helvetica" size:13.0];
text_desc.editable=NO;
text_desc.tag=1;
}
次に、srollview のコンテンツ サイズを設定します。
scroll.contentSize = CGSizeMake(0,total*87);
//配列型のサブストリングをループして、実行時にテキストフィールドを追加します
for (int i = 0; i < [substrings count]; i++)
{
CGRect frame = CGrectMake(0, i * 40, 100, 30);
UITextField * txtDynamic = [[UITextField alloc] initWithFrame: frame];
txtDynamic.text = [substrings objectAtIndex:i];
//add as subview
[view addSubview:txtDynamic];
//if you are not using ARC release the txtDynamic
}
注 UITextFieldの数が多い場合、つまり画面から消える場合は、UITextFieldをUIScrollViewに追加すると、そのサイズとコンテンツサイズを動的にすることができます。
これがあなたにいくつかの手がかりを与えることを願っています。
ちょっと仲間は、スクロールビューを1つ取り、その中ですべてのテキストビューを次のContentSize
ように設定するだけです
ここで例を挙げます。
注:これは単なる例です。名前を 1 つ取りUIScrollView
、scrview という名前を付けてから、すべてを追加UITextField
します。
テキストフィールドにデータを追加した後にこのコードを追加します
txt1.frame = CGRectMake(txt1.frame.origin.x, txt1.frame.origin.y, txt1.frame.size.width, txt1.contentSize.height);
float txtscreen1 = txt1.frame.origin.y + txt1.contentSize.height + 10;
txt2.frame = CGRectMake(txt2.frame.origin.x, txtscreen1, txt2.frame.size.width, txt2.contentSize.height);
float txtscreen2 = txt2.frame.origin.y + txt2.contentSize.height + 10;
txt3.frame = CGRectMake(txt3.frame.origin.x, txtscreen2, txt3.frame.size.width, txt3.contentSize.height);
//.....and so on to 10
float txtscreen10 = txt3.frame.origin.y + txt3.contentSize.height + 10;
txt10.frame = CGRectMake(txt10.frame.origin.x, txtscreen10, txt10.frame.size.width, txt10.contentSize.height);
float scrollviewscreen = txtscreen10.frame.origin.y + txtscreen10.frame.size.height + 20;
scrview.contentSize=CGSizeMake(320, scrollviewscreen);//take scrollview
これがお役に立てば幸いです....
:)