2011-12-02 50 views

回答

4

你可以从图像创建一个新的视图,然后将它添加到调用addSubview的单元中。下面是一个例子一经推出设置角落:

- (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]; 

     CGRect cornerFrame = CGRectMake(x, y, width, height); 
     UIImageView * corner = [[UIImageView alloc] initWithFrame:cornerFrame]; 
     [corner setImage:[UIImage imageNamed:@"corner.jpg"]]; 

     [cell.contentView addSubview:corner]; 
    } 

    return cell; 
} 
+0

这将无法正常工作...细胞得到重用,因此当你以这种方式实现它来添加很多这样的每个细胞。 –

+0

这就是调用'addSubview'的例子。他可以在任何他想要的地方使用它。 – Dimme

+0

在这个特定的地方,它会突破:)唯一比糟糕的代码示例更差的代码示例。 –

0

它可能只是一个在细胞图像。没有太花哨的东西,只是你自己的磨坊标准运行自定义UITableViewCell