デュードは
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
if ([text isEqualToString:@"\n"]) {
}
else
{
NSString *yourstring = [[NSString alloc]init];
yourstring = textView.text;
CGSize s = [yourstring sizeWithFont:[UIFont systemFontOfSize:15] //define your textview font size
constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding
lineBreakMode:UILineBreakModeWordWrap];
CGRect frame = CGRectMake(0.0f, s.height+10, 320.0f, 20);//use YourImageView. height and width
YourImageView.frame=frame;
}
return YES;
}
は私に知らせて...私のコードを使用してください。あなたが任意の難しさを見つけたら...
編集 * 追加.... *
//imgSwipe2 is my UIImgaeView you can use your imageview. May Be i forgot to release some object and i am sure that you can handle but it's working fine,
-(void)textViewDidChangeSelection:(UITextView *)textView
{
NSRange range = textView.selectedRange;
if(range.location<textView.text.length)
{
NSString * firstHalfString = [txtView.text substringToIndex:range.location];
CGSize s = [firstHalfString sizeWithFont:[UIFont systemFontOfSize:15]
constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding
lineBreakMode:UILineBreakModeWordWrap];
if(s.height<imgSwipe2.frame.origin.y)
{
// You can use this code any number of image
imgSwipe2.frame = CGRectMake(imgSwipe2.frame.origin.x, s.height, imgSwipe2.frame.size.width, imgSwipe2.frame.size.height);
}
else
{
// Do what ever you want to do
NSString * firstString1 = textView.text;
CGSize s = [firstString1 sizeWithFont:[UIFont systemFontOfSize:15]
constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding
lineBreakMode:UILineBreakModeWordWrap];
imgSwipe2.frame = CGRectMake(imgSwipe2.frame.origin.x, s.height, imgSwipe2.frame.size.width, imgSwipe2.frame.size.height);
}
}
}
希望、これはあなたが...それは働いた
出典
2012-04-24 04:24:05
Nit
...お楽しみに役立ちます私の魅力のように。私はあなたに感謝の言葉を持っていない。あなたの助けを大変ありがとう。私はそれを何度もアップワイヤーしてもらいたいです。しかし、それは1つのイメージでうまくいくでしょう。イマペレムテキストやイメージのようなものを作成し、イメージの後にテキストを書くことができます。 – Gypsa
現在の状況でイメージとテキストの順序を変更したいのですか?あなたのシナリオを説明できますか?だから、私はあなたが実際に望んでいるものを理解することができます。 – Nit
私のシナリオは次のとおりです: - ユーザーがテキストを書き込んで複数の画像を追加できるテキストビューです。現在、ユーザーはテキストの行を入力して画像を追加します(eg.abcdefghとimage1)。 (例:.abcdefghとimage1、ijklmnopとimage2)とテキストなどがあります。これは私が実装する必要があります。ユーザーがこの場合ijkにカーソルを移動すると、画像1はその位置にありますが、画像2は移動しますユーザーがカーソルをabcに移動してそこから書き込みを開始すると、この場合、イメージイメージ1とイメージ2の両方が下に移動します。 – Gypsa