2011-12-14 10 views
1

私は自分のTableViewに背景画像を使用しようとしていたので、画面上にテーブル全体を表示するのに十分なデータがないときに残ったtableviewセルを取得しませんでした。このURLに従いますが、はるかに簡単:http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.htmlUITableViewCellとUITableViewの背景色を設定する

私のUITableViewへの出口を持っているのViewControllerで次の操作を行います。

UIImage *backgroundTableImage = [UIImage imageNamed:@"form_background.png"]; // basically a gray->white gradient 
    UIImageView *tableBackgroundImageView = [[UIImageView alloc] initWithImage:backgroundTableImage]; 
    tableBackgroundImageView.frame = self.TableView.bounds; 
    self.TableView.backgroundView = tableBackgroundImageView; 
    [tableBackgroundImageView release]; 
    self.backgroundColor = [UIColor clearColor]; 

は、それから私は、私はIBで作成するのUITableViewCellのカスタムサブクラスを持っています。 IBでは、背景は白 - デフォルトに設定されています。私の細胞はすべて透明で、私は自分の背景だけを見ます。どのようにして細胞を白色に保つのですか?

+0

この行 'tableBackgroundImageView.frame = self.TableView.bounds'は正しくないようです。これがあなたが望むことをしていると確信していますか? – gurooj

答えて

0

まず、.hファイルのビューを取得します。UIView * newView;そのプロパティを宣言し、それ以上の質問が私をノックしてください場合はcellForRowAtIndexPath

if(cell==nil){ 

     tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imagename.png"]]; 

................ 
......... 
newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)]; 
[cell.contentView addSubview:newView]; 
................ 
............... 
} 
if(indexPath.row == 0){ 

newView.backgroundColor = [UIColor blueColor]; 

} 
if(indexPath.row == 1){ 

newView.backgroundColor = [UIColor redColor]; 

} 
if(indexPath.row == 2){ 

newView.backgroundColor = [UIColor greenColor]; 

} 

に今すぐあなたの.mファイル

でそれをsynhesize。

関連する問題