1

我正在编写此代码以将 plist 加载到 2 textview 但我希望他们根据我所做的内容大小调整它们的高度但我希望第二个 uitextview 从第一个结束的地方开始..请帮助

 for (int i = 0; i < arrresult.count; i++) {


    NSArray *sorteddetail = [self.arrresult sortedArrayUsingFunction:sortint context:NULL];
    DuaObject *duaobj2 = [[DuaObject alloc] initWithFilePath:[sorteddetail objectAtIndex:i]];
    [duaobj2 loadFile];

    CGRect frame;
    frame.origin.x = self.scrollmain.frame.size.width * i;
    frame.origin.y = 0;
    frame.size = self.scrollmain.frame.size;

    UITextView *subview = [[UITextView alloc] initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+10, 230, 120)];
    UITextView *subview2 = [[UITextView alloc]initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+160,230, 120)];




    subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BG_text.png"]];
    subview2.backgroundColor = [UIColor whiteColor];

    [subview setFont:[UIFont boldSystemFontOfSize:14]];
    [subview2 setFont:[UIFont boldSystemFontOfSize:14]];

    subview.layer.cornerRadius = 10 ;
    subview2.layer.cornerRadius = 10;

    NSString *p = [duaobj2 dua_arabic];
    NSString *b = [duaobj2 eng_trans];

    subview.text = p;
    subview2.text = b;

    [self.scrollmain addSubview:subview];
    [self.scrollmain addSubview:subview2];

    subview.editable = NO;
    subview2.editable = NO;

    subview.textColor = [UIColor blackColor];
    subview2.textColor = [UIColor blackColor];


    subview.backgroundColor = [UIColor whiteColor];
    subview2.backgroundColor = [UIColor whiteColor];


    scrollmain.showsHorizontalScrollIndicator = NO;

    CGRect frame1 = subview.frame;
    CGRect frame2 = subview2.frame;

    frame1.size.height = subview.contentSize.height;
    frame2.size.height = subview2.contentSize.height;

    subview.frame = frame1;
    subview2.frame = frame2;



}
4

1 回答 1

0

您可以为此使用两个 UIWebView。从 plist 获取文本数据后,将其重定向到特定的 Web 视图。并使用 [webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] 方法获取像素高度。根据像素的高度,您可以重新调整网页视图框架。

编辑:看这个:如何根据内容调整 UITextView 的大小? 它会帮助你。

于 2013-02-19T07:42:00.817 回答