[英]How can I make an image in a grouped tableview cell the width of the screen?
I have large images displayed in a grouped tableview. 我在分组的表格视图中显示了大图像。 I would like the images to fill the entire width of the screen.
我希望图像填充屏幕的整个宽度。 I have been able to make this work using a tableViewCell interface builder, but in an attempt to improve performance I am now trying to do this programmatically.
我已经能够使用tableViewCell接口构建器来完成这项工作,但是为了提高性能,我现在正尝试以编程方式进行此操作。
However, I have not been able to get the image to be flush against the left side of the screen. 但是,我无法使图像与屏幕左侧齐平。 It seems to be using the default position of the cells in the grouped tableview.
似乎在使用分组表格视图中单元格的默认位置。
I was able to make it work using a plain tableview, but then the section headers anchor on the top of the screen and I need them to scroll. 我能够使用普通的tableview使其工作,但是节标题停在屏幕顶部,因此我需要它们滚动。
Any ideas how to do this programmatically? 任何想法如何以编程方式执行此操作? Here's my original code below.
这是下面的原始代码。 Thanks!
谢谢!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyTableViewCellIdentifier = @"Cell";
MyTableViewCell *cell = (MyTableViewCell *)
[tableView dequeueReusableCellWithIdentifier: MyTableViewCellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
for(id currentObject in nib)
{
cell = (DetailTableViewCell *)currentObject;
}
MyAppAppDelegate *appDelegate = (MyTableViewCell *)[[UIApplication sharedApplication] delegate];
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *MainImagePath = [Path stringByAppendingPathComponent:
([[appDelegate.myDictionaryOfImages objectAtIndex:indexPath.section] objectForKey:@"LargeImage"])];
cell.myLargeImage.image = [UIImage imageWithContentsOfFile:MainImagePath];
return cell;
}
I finally got it working. 我终于让它工作了。 Here is my final code.
这是我的最终代码。
#define PHOTO_TAG 1
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Photo";
UIImageView *photo;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIImage *theImage = [UIImage imageNamed:[[appDelegate.sectionsDelegateDict objectAtIndex:indexPath.section] objectForKey:@"MainImage"]];
imageHeight = CGImageGetHeight(theImage.CGImage);
imageWidth = CGImageGetWidth(theImage.CGImage);
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
photo = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageWidth, imageHeight)] autorelease];
photo.tag = PHOTO_TAG;
[cell addSubview:photo];
} else {
photo = (UIImageView *) [cell viewWithTag:PHOTO_TAG];
[photo setFrame:CGRectMake(0, 0, imageWidth, imageHeight)];
}
photo.image = theImage;
return cell;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.