【发布时间】:2015-08-03 15:29:31
【问题描述】:
纵横比 “Scale To Fill” 和 “Aspect Fit” 使图像拉伸到整个 UIImageView 大小。如何使用 Aspect Fill" 来处理 UITableViewCell 内的 UIImageView。UITableViewCell 内的 UIImageView 在 Aspect Fill 中超出屏幕。我想让图像采用原始尺寸 而不是拉伸,但我想防止它在其下部单元格上方形成重叠。如果它低于下部单元格,则更好。
第一个缩放填充第二个纵横比填充
我使用以下来选择图像模式
我的代码
细胞.m
- (void)awakeFromNib {
_img.clipsToBounds = YES;
_img.contentMode = UIViewContentModeScaleAspectFill;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
VCUIViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
static NSString *CellIdentifier = @"NoticiasDetailImageCell";
NoticiasDetailImageCell *cell = (NoticiasDetailImageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
cell = (NoticiasDetailImageCell *)[nib objectAtIndex:0];
}
cell.img.image = self.img;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
【问题讨论】:
-
下面的解决方案对您有用吗?如果是,请接受答案。谢谢
标签: ios objective-c uitableview uiimageview aspect-ratio