1

テキストビューがあり、テキストビューに画像を追加する必要があります。テキストビューのアイデアは、テキストと画像、および画像テキストの後に想定できます。テキストビュー、テキストは画像の後ろに表示されます。画像がカーソル位置の下にあり、テキストを編集しているため、画像も前後に移動する必要があると想定しています。テキストの編集時に画像をシフトします。私のアプリの展開ターゲットは 5.0 なので、ios 5.0 で提供される新機能を含めることができます。

画像では、テキストを編集するときにテキストが画像ビューの後ろに表示される方法が示されています。そのため、画像ビューをシフトする必要があります。

助けてください。私はここで立ち往生しています。

前もって感謝します。

4

1 に答える 1

1

おい、私のコードを使って...

- (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-24T04:24:05.377 に答える