有点uitextview的位置

时间:2013-02-19 07:30:57

标签: iphone ios plist uitextview frame

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

 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;



}

1 个答案:

答案 0 :(得分:0)

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

编辑: 看一下:How do I size a UITextView to its content? 它会对你有所帮助。