如何在自定义单元格中显示自定义大小的图像
问题描述:
我的iPhone应用程序图像在表格单元右侧从xml提取中提取。知道我想以固定大小显示它们,任何人都可以帮助我。 波纹管是代码如何在自定义单元格中显示自定义大小的图像
int blogEntryIndex1 = [indexPath indexAtPosition: [indexPath length] -1];
imgstring=[[blogEntries objectAtIndex: blogEntryIndex1] objectForKey: @"image"];
NSURL *url = [NSURL URLWithString:imgstring];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
cell.imageView.image=img;
cell.textLabel.text=headline;
在此先感谢,我将等待
答
设置您的UIImageView的内容模式UIViewContentModeScaleAspectFit或UIViewContentModeCenter如果你的图片不需要任何缩放。
[yourImageView setContentMode:UIViewContentModeScaleAspectFit];
查看API中的示例。有一种更好的方式来为表格视图单元格加载图像。 http://developer.apple.com/iphone/library/samplecode/LazyTableImages
而且为了更好地理解表视图细胞的解剖阅读: http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html