1. UITableViewCellのセルに背景画像を表示する。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self._listitemTable dequeueReusableCellWithIdentifier:@"HogeViewCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"HogeViewCell"] autorelease];
UIColor *col = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"backupgroundTableCell.png"]];
[tableView setBackgroundColor:col];
[col release];
}
2. Viewの背景として画像を表示する。
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *backImageview = [[[UIImageView alloc] initWithFrame:self.view.bounds] autorelease];
[backImageview setImage:[UIImage imageNamed:@"backupground.png"]];
[self.view addSubview:backImageview];
上記1.の場合、セルに表示されるデータがない場合は背景画像が表示されないが、上記2.の場合はViewが表示されたときに背景画像も表示される。
タグ:iPhone