iphone - 让 UIImageView 填满整个 UITableViewCell

标签 iphone ios objective-c uitableview

你如何使整个 UITableViewCell 成为自定义图像?我这样做是为了原型(prototype)设计,但我找不到从哪里开始。我基本上需要 3 个具有相同图像的 UITableViewCells - 所以它们都是可重复使用的单元格。

关于如何做到这一点的任何想法?谢谢。

最佳答案

我想你想要的是:backgroundView UITableViewCell 的属性(property)

你可以这样做:

-(void)  tableView:(UITableView*)tableView 
   willDisplayCell:(UITableViewCell*)cell 
 forRowAtIndexPath:(NSIndexPath*)indexPath;
{
    static UIImage* bgImage = nil;
    if (bgImage == nil) {
        bgImage = [[UIImage imageNamed:@"myimage.png"] retain];
    }
    cell.backgroundView = [[[UIImageView alloc] initWithImage:bgImage] autorelease];
}

或直接使用:
((UIImageView*)cell.backgroundView).image = [UIImage imageNamed:@"customBackground"];
((UIImageView*)cell.selectedBackgroundView).image = [UIImage imageNamed:@"selectedBackground"];

关于iphone - 让 UIImageView 填满整个 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14318336/

相关文章:

iphone - PNG 和 UI 图像优化

ios - XCode iPhone 模拟器看起来不像 iPhone

ios - OCMock 设置模拟类,其属性并获得基本了解

iphone - UIGestureRecognizer 结尾

iphone - 如何比较 NSDates 以查找数组中最早和最晚的日期?

iphone - 游戏中如何使用多线程(iOS)

iphone - 如何将 ViewController 更改为另一个没有 ".xib"的 ViewController ?

ios - 以编程方式创建一个在横向和纵向工作的 UIPickerView

iphone - iOS 上的圆形按钮

ios - 设置事件 "repeats every month"的重复发生而不是 "repeats every month, each 31st"ios