iphone - 关于绘制单元格矩形的解决方案

标签 iphone ios

How to customize the background/border colors of a grouped table view cell?

阅读这篇文章后,我尝试使用这个解决方案。这是我的代码,在 tableViewDelegate 方法中:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
   CustomCellBackgroundView *customBackground = [CustomCellBackgroundView alloc];

    [customBackground setBorderColor:[UIColor blackColor]];
    [customBackground setFillColor:[UIColor redColor]];
    [customBackground setPosition:0]; //i'll deal with that later

    [cell setSelectedBackgroundView:customBackground];
    [customBackground release];


    UIImageView* selectedBackgroundCell = [[[UIImageView alloc] initWithFrame:CGRectNull] autorelease];
    [selectedBackgroundCell setImage:[UIImage imageNamed:@"cell_bg_50_hover.png"]];
    [customBackground drawRect:selectedBackgroundCell.frame];

    [cell setSelectedBackgroundView:selectedBackgroundCell];

    //standard background color
    [cell setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_bg_50.png"]]];
}

但不幸的是,它并没有改变任何东西。你知道我做错了什么吗?

最佳答案

我相信无论何时制作 View ,您都应该为此指定一些框架。 因此,为自定义背景和背景指定框架 CGRectZero....

以下仅在我测试时对我有用。

 UIView *bkview = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

    bkview.backgroundColor = [UIColor redColor];

    cell.selectedBackgroundView = bkview;

关于iphone - 关于绘制单元格矩形的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7309580/

相关文章:

javascript - 即使页面发生变化,jQuery Mobile 或 Sencha Touch 如何在 iPhone 中隐藏地址栏?

iphone - 我们需要 iPhone/iPad 来开发它吗?

iphone - 自定义 editingAccessoryView 行为不可预测

ios - 了解 UIDynamics 如何计算位置

iphone - 在 4.3.3 设备上从 xcode 构建/运行 IOS 5.0

ios - 加载 View Controller 后如何使用计时器设置进度条

ios - 无法在 SpriteKit Swift 中使用 SKVideoNode 播放视频

ios - NSOperation 访问 isCancelled in main

iphone - 让 UITableViewController 在旋转时刷新其 tableview 的最佳方法是什么?

ios - XCODE 中的 Json.Net 错误 - System.Reflection.Emit