2011-07-26 105 views
0

我想添加一個UIScrollView在我的TableViewCell。它看起來進行得很順利,但是當我滾動時,標籤從右側進入,它進入單元格上方,但是當文本移動到標籤的左側邊緣時,它就像我想要的那樣消失在標籤後面它來。UIScrollView裏面的UITableViewCell

有什麼建議嗎?

UIScrollView *previewScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 80.0)]; 
     previewScrollView.backgroundColor = [UIColor clearColor]; 
     [previewScrollView setContentSize:CGSizeMake(500, 60.0)]; 
     previewScrollView.showsHorizontalScrollIndicator = YES; 

     UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 3.0, 500.0, 20.0)]; 
     headerLabel.font = [UIFont boldSystemFontOfSize:14.0]; 
     headerLabel.backgroundColor = [UIColor clearColor]; 
     headerLabel.text = @"My long text string that I hope work out ok"; 
     [previewScrollView addSubview:headerLabel]; 

     [[cell contentView] addSubview:previewScrollView];   
     //[cell addSubview:previewScrollView]; 
     [previewScrollView release]; 

回答

0

從爲我滾動正確的,它的細胞

的單元格上方上面就會出現,在Y或Z軸?

如果它位於y軸上方,則可以嘗試在滾動視圖上設置clipsToBounds。這使得子視圖只能在他們的超視圖區域內繪製。

如果是以上在z軸,其中一些在前面應該是後面,嘗試使用:

[[cell contentView] insertSubview:previewScrollView atIndex:0]; 

在索引0處插入確保視圖在上海華所有其他子視圖的後面。

+0

我正在使用分組的tableview,因此您可以在滾動時在單元格的小可見tableview背景區域上看到文字疊加層。 – Convolution