xcode 左侧的 UITableView 图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7102327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UITableView image on the left hand side
提问by Arpit B Parekh
Possible Duplicate:
adding images to UItableView
可能的重复:
将图像添加到 UItableView
I want to add image in UITableView in the left hand side how could I add it?
我想在左侧的 UITableView 中添加图像,我该如何添加?
采纳答案by Ravi Chokshi
Try This ,
尝试这个 ,
UIImageView *backgroundCellImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 80)];
backgroundCellImage.image=[UIImage imageNamed:@"ImageName.png"];
[cell.contentView addSubview:backgroundCellImage];
[backgroundCellImage release];
回答by JonasG
In the cellForRowAtIndexPath
method add:
在cellForRowAtIndexPath
方法中添加:
cell.imageView.image = [UIImage imageNamed:@"img.png"];
and thats it! really easy!
就是这样!真的很容易!
If you are using custom cells then you need to add an ImageView to your custom cell in IB. Then create, connect and synthesize an IBOutlet for it and add this code to the cellForRowAtIndexPath
method:
如果您使用自定义单元格,那么您需要在 IB 中将 ImageView 添加到您的自定义单元格。然后为它创建、连接和合成一个 IBOutlet 并将此代码添加到cellForRowAtIndexPath
方法中:
cell.yourImageOutlet.image = [UIImage imageNamed:@"img.png"];
回答by Hadi
Just add image in cellForRowAtIndexPath method
..
只需在cellForRowAtIndexPath method
..
cell.imageView.image = yourImage;
回答by alloc_iNit
Either you can add UIImageView to the desired position by setting its frame...
您可以通过设置其框架将 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];
or you can go with following code too...
或者你也可以使用以下代码......
cell.myImageView.image = [UIImage imageNamed:@"image.png"];
cell.imageView.contentMode = UIViewContentModeCenter;
回答by Ajay Sharma
just use :
只需使用:
if you are using UITableViewCellStyleDefaultthen you don't need to customize the look of of tableviewcells.
如果您使用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;
}