Iphone UITableView背景图像

Iphone UITableView背景图像,iphone,uitableview,Iphone,Uitableview,我正在尝试设置一个具有滚动背景的表视图。背景是一个重复的云图像 作为实现此功能的初步尝试,我使用了以下代码: - (void)viewDidLoad { aTableView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]]; aTableView.separatorStyle = UITableViewCellSeparatorStyleNone; } -

我正在尝试设置一个具有滚动背景的表视图。背景是一个重复的云图像

作为实现此功能的初步尝试,我使用了以下代码:

- (void)viewDidLoad {
    aTableView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]];
    aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
        [cell setBackgroundColor:[UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]]];
}
然而,这并不像我所希望的那样奏效。图像被放置为每个单元格的背景(这很好),但也作为表视图的背景,因此当用户滚动超过屏幕边界并使用反弹时,将显示相同的云背景。这会产生不希望的重叠效果

我想要的是每个单元格都有这个重复的图像(这样它就可以随着表格滚动),但是表格视图的背景是纯黑色。这可能吗

我知道我可以将图像添加到自定义单元格并将其发送到后面,但这似乎是一个占用大量内存的解决方法

干杯


我已使用以下代码对其进行了排序:

- (void)viewDidLoad {
    aTableView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]];
    aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
        [cell setBackgroundColor:[UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]]];
}

这是将UIColor设置为UIImage的最佳方法还是资源密集型方法?

您正在设置
UITableView
的背景。不是
UITableView单元格的背景色。

这可能有助于设置
UITableView
的背景色:

我遇到了完全相同的问题,只是在实现的中途,我们决定放弃设计,转而使用定制的tableview单元格。我们最初的设计看起来像一个记事本,每行上都有单元格

对UITableViewCell进行子类化似乎是一项困难的任务,但如果您将来需要自定义该单元格,并且它似乎可以满足您的要求,那么它是值得的。如果您感兴趣,我可以在我的项目中为您发布代码,但是请注意,您不会在UITableView本身上拥有背景,而只会在单元格上拥有背景

编辑:发布与创建自定义UITableViewCell相关的代码: 我的手机叫HotOffersCell, 这里是HotOffersCell

#import <UIKit/UIKit.h>
@interface HotOffersCell : UITableViewCell {
    IBOutlet UILabel *mainLabel;
    IBOutlet UILabel *subLabel;
    IBOutlet UILabel *price;
    IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UILabel *mainLabel;
@property (nonatomic, retain) UILabel *subLabel;
@property (nonatomic, retain) UILabel *price;
@property (nonatomic, retain) UIImageView *imageView;

@end
我还有一个HotOfferCell.xib,这个文件包含一个UITableViewCell,没有视图,我链接了周围所有相关的标签,仅此而已,它提供了一种很好的图形方式,可以在不更改代码的情况下编辑标签上的位置,我甚至让我的兄弟修改了这个=)


我希望这会有所帮助

那么这也会为单个细胞设置背景吗?这是正确的。UITableView的背景与UITableViewCell的背景是分开的。这太好了,我现在用背景实现了一个自定义单元格。你能添加你的代码吗?ThanksIve通过编辑我的评论在这里发布了代码,希望这对您有所帮助。