4

次のコードを使用して繰り返し背景画像をUITableViewに設定すると、問題ありません。

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

しかし、それを使用して次のコードで繰り返し背景画像をUITableViewCellに設定すると、何も起こりません。理由はわかりません。このセルにも背景色を設定できません。

cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];

これを行う方法を知っている人はいますか?私を助けてください!

4

2 に答える 2

9
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell.png"]];

これはこのコードブロック内に入ります:

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

TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
        cell = [[[RecipeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell.png"]];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell-on.png"]];
    }    
// Configure cell

return cell;
}

選択した画像をその中に設定する方法も確認できます:selectedBackgroundView。

cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell-pressed.png"]];

繰り返すかどうかはわかりませんが、backgroundViewでcontentModeを設定できると確信しています。

于 2010-07-13T04:48:25.103 に答える
1

ああ、思ったより簡単です。次のコードで背景画像を設定する必要があります。

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];

セルの背景ビュー全体がこの背景画像で自動的に塗りつぶされます。:)

于 2010-07-14T03:41:06.007 に答える