resizableImageWithCapInsets不会拉伸UITableViewCell背景的图像

时间:2013-02-26 14:40:07

标签: iphone ios objective-c uitableview

我正在自定义UITableViewCell的背景。我使用以下代码:

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

  NSString *cellIdentifier = @"MenuItemCell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
  }
    UIImageView* uiv= [[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"bkgCell44.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)]];
uiv.frame = CGRectMake(0, 0, 320, 44);
cell.backgroundView = uiv;
cell.backgroundColor = [UIColor clearColor];

return cell;

}

显示图像,但它根本没有拉伸......

有什么帮助指出我做错了什么? 相同的代码用于按钮和导航栏...

1 个答案:

答案 0 :(得分:0)

if (cell == nil) 
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

   UIImageView* uiv= [[UIImageView alloc]init];
   uiv.image = [UIImage imageNamed:@"bkgCell44.png"];
   uiv.frame = CGRectMake(0, 0, 320, 44);
   uiv.contentMode = UIViewContentModeScaleAspectFit;
   cell.backgroundView = uiv;
   cell.backgroundColor = [UIColor clearColor];
}