2013-03-19 76 views
0

我希望textview位於我的表格內部的滾動視圖之前,以便滾動視圖滾動並且標題保持放置狀態。在uiScrollView之前添加uiTextView

[Title goes here] - it does not move with the scrollview 
--------------------- 
|     | 
| ScrollView  | 
|     | 
--------------------- 

這是我的代碼,TextView的出現滾動視圖後面。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"]; 
    } 

    NSInteger numberOfViews = 10; 
    UIScrollView *vwScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1280, 200)]; 

    for (int i = 0; i < numberOfViews; i++) { 
     CGFloat xOrigin = i * 250; 
     UITextView *titleView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 1280, 20)]; 
     titleView.text = @"Title"; 
     [titleView setFont:[UIFont fontWithName:@"HelveticaBold" size:32]]; 


     UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, 250, 180)]; 
     awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5/i/10 blue:0.5 alpha:1]; 
     [awesomeView.layer setBorderColor:[UIColor whiteColor].CGColor]; 
     [awesomeView.layer setBorderWidth:10.5f]; 
     awesomeView.layer.shadowPath = [UIBezierPath bezierPathWithRect:awesomeView.bounds].CGPath; 

     [cell.contentView addSubview:titleView]; 
     [vwScroll addSubview:awesomeView]; 

    } 
    vwScroll.contentSize = CGSizeMake(250 * numberOfViews, 200); 

    [cell.contentView addSubview:vwScroll]; 

    return cell; 
} 

回答

1

爲什麼不能你剛纔設置你的titleview的,比方說,(0,0,width,titleHeight)的框架,然後設置你的滾動視圖的框架(0,titleHeight,width,cellHeight-titleHeight)

這隻會將標題放在單元格的頂部,將其設置爲高度,無論您將titleHeight設置爲什麼,並將scrollView放置在單元格的底部,並將其設置爲高度細胞。

+0

看起來TextView在scrollview的後面.. – Harry 2013-03-19 07:49:09

+1

您是否將scrollView的Y座標設置爲與textView的高度相同? – Jsdodgers 2013-03-19 07:55:00

+0

啊這就是問題!男人,我沒有想到這一點,謝謝,添加到您的答案,並給我一個綠色標記:-) – Harry 2013-03-19 07:56:43

相關問題