arn*_*lja 1 objective-c uitableview uiimageview ios4
我使用图像来显示UITableViewCell的整个内容,并使用backgroundView属性进行设置.
我的问题是它总是按比例缩放以适应细胞.有没有办法在这种情况下禁用缩放,所以我只提供480像素版本,它只是在方向为肖像时被裁剪?
我是这样做的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"menu.0%d.large.png", indexPath.row+1]]];
UIImageView *selectedBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"menu.0%d.large.selected.png", indexPath.row+1]]];
cell.backgroundView = bgView;
cell.selectedBackgroundView = selectedBgView;
[bgView release];
[selectedBgView release];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
当方向改变时,我尝试使用两个版本的图像在它们之间切换.到目前为止,这也有效,但它的缺点是在处理动画时总能看到缩放.
谢谢你的帮助
阿恩
设置背景图像视图的内容模式.
bgView.contentMode = UIViewContentModeTopLeft;
selectedBgView.contentMode = UIViewContentModeTopLeft;
Run Code Online (Sandbox Code Playgroud)
这告诉UIImageView它将其图像放在左上角而不是缩放它以适应.