iphone UITableViewCell добавить изображение - PullRequest
0 голосов
/ 14 октября 2011

У меня есть подкласс TableViewController и метод initWithStyle, например:

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {        
        [self.view setFrame:CGRectMake(0, 200, 320, 280)];
    }
    return self;
} 

Я хочу добавить фоновое изображение для каждого моего TableViewCell, и изображение отображается, но оно просто отображает часть изображения (мой размер изображения 320 × 48), мой код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.imageView.image = [UIImage imageNamed:@"cell_bg_light.png"];    
    return cell;
}

и результат: enter image description here

1 Ответ

0 голосов
/ 14 октября 2011

Вы можете попробовать это.

cell.contentView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"cell_bg_light.png"]];

или вы можете использовать

UIView *cellBackView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cellBackView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"cell_bg_light.png"]];
cell.backgroundView = cellBackView;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...