2011-06-22 21 views
1

私は2つのセル(カスタムtableviewcells)とログイン用のボタンを持つuitableviewを持っています。私はプログラムで作った。今度は、2つのカスタムセルとボタンの背後に背景画像を配置したいと思います。私はIBに入り、画像ビューをテーブルビューの上に置き、背景として必要な画像を置く。次に私はviewDidLoadに入り、このビットをコードtblSimpleTable.backgroundColor = [UIColor clearColor];に入れて、tableviewsの背景色をクリアします。UITableViewに背景画像が表示されない

それは次のようになります。

enter image description here

しかし、背景は表示されません。誰もがこれを修正する方法を知っていますか?

ありがとうございました。

のviewDidLoadあなたはUITableViewオブジェクトのbackgroundViewプロパティを使用していないのはなぜ

- (void)viewDidLoad { 
[super viewDidLoad]; 

self.dataSourceArray = [NSArray arrayWithObjects: 
         [NSDictionary dictionaryWithObjectsAndKeys: 
         @"UITextField", kSectionTitleKey, 
         @"TextFieldController.m: textFieldNormal", kSourceKey, 
         self.textFieldNormal, kViewKey, 
         nil], 
         nil]; 

UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
loginButton.frame = CGRectMake(60,140,200,38); // position in the cell and set the size of the button 
[loginButton setTitle:@"Login" forState:UIControlStateNormal]; 
// add targets and actions 
[loginButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
// add to a view 
[self.view addSubview:loginButton]; 

tblSimpleTable.backgroundColor = [UIColor clearColor]; 
//tblSimpleTable.backgroundView = nil; 

//UIImageView *imageView = [[UIImageView alloc] initWithImage:@"Background-Red.png"]; 
//imageView.frame = tblSimpleTable.frame; 
//tblSimpleTable.backgroundView = imageView; 

self.title = NSLocalizedString(@"TextFieldTitle", @""); 

// we aren't editing any fields yet, it will be in edit when the user touches an edit field 
self.editing = NO; 
} 
+0

tblSimpleTable.backgroundView = nil; 

を追加しますか?どのようにこれをやったのか、いくつかのコードを見せてくれますか? – Manuel

+0

ImageViewとそのImageViewにラベルとすべてのものをNibファイルに入れます –

+0

@ dragon112 + Marvin:** viewDidLoad **のコードは上記のようになります。 –

答えて

0

あなたはおそらくうまくいくはずです。まだこれを試してください:
はあなたが上に画像を置くのviewDidLoad

+0

@Nitish:残念ながら、それは動作しません。私はいくつかの投稿がIBにイメージを置く必要があると言っているのを見ました - **送り返し**。しかし、IBの** send to back **オプションが無効になっているので、それはできません。なぜなのかご存知ですか?ありがとう。 –

+0

私はこれが必要ないとは思わない。あなたは、テーブルセルの背後に、または完全なビューの後ろに画像を配置したいですか? – Nitish

+0

@Nitish:テーブルセルとボタンの後ろに画像を配置したい。したがって、画像は背景であり、テーブルセルとボタンは画像の上にあります。どのようにするか知っていますか?ありがとう。 –

1

?あなたはそうも問題になることはありません二行目をスキップ枠を設定しない場合はもちろん

UIImageView * imageView = [[UIImageView alloc] initWithImage:yourBackgroundImage]; 
imageView.frame = tblSimpleTable.frame; 
tblSimpleTable.backgroundView = imageView; 

backgroundViewがリサイズされます。

+0

それを 'viewDidLoad'にも入れますか? –

+0

うん。それはそれを行うための正しい場所でなければなりません。 –

関連する問題