伙计 使用我的代码...
- (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);
}
}
}
希望,这会帮助你...享受...