【发布时间】:2011-08-18 04:21:55
【问题描述】:
【问题讨论】:
标签: iphone objective-c xcode
【问题讨论】:
标签: iphone objective-c xcode
在cellForRowAtIndexPath方法中添加:
cell.imageView.image = [UIImage imageNamed:@"img.png"];
就是这样!真的很简单!
如果您使用的是自定义单元格,那么您需要将 ImageView 添加到 IB 中的自定义单元格中。然后为其创建、连接和合成一个 IBOutlet 并将此代码添加到 cellForRowAtIndexPath 方法中:
cell.yourImageOutlet.image = [UIImage imageNamed:@"img.png"];
【讨论】:
只需将图片添加到cellForRowAtIndexPath method..
cell.imageView.image = yourImage;
【讨论】:
试试这个,
UIImageView *backgroundCellImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 80)];
backgroundCellImage.image=[UIImage imageNamed:@"ImageName.png"];
[cell.contentView addSubview:backgroundCellImage];
[backgroundCellImage release];
【讨论】:
您可以通过设置 UIImageView 的框架将其添加到所需位置...
UIImageView *postImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 34, 300, 225)];
postImage.image = [UIImage imageWithData:data];
[postImage setContentMode:UIViewContentModeScaleAspectFill];
postImage.clipsToBounds = YES;
[cell addSubview:postImage];
[postImage release];
或者您也可以使用以下代码...
cell.myImageView.image = [UIImage imageNamed:@"image.png"];
cell.imageView.contentMode = UIViewContentModeCenter;
【讨论】:
只需使用:
如果您使用的是 UITableViewCellStyleDefault,则无需自定义 tableviewcells 的外观。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
// Configure the cell...
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.imageView.image=[UIImage imageNamed:@"ImageName.png"];
cell.textLabel.text=@"Text";
return cell;
}
【讨论】: