繁体   English   中英

正确使用iOS Xcode中的宽高比

[英]correctly use aspect ratio aspect fill in iOS Xcode

纵横比“缩放以填充”“纵横比匹配”使图像拉伸到整个UIImageView大小。 如何使用Aspect Fill”来处理UITableViewCell内的UIImageView。UITableViewCell内的UIImageView在Aspect Fill中用尽了屏幕。我想使图像采用原始大小,而不是拉伸,但我想防止图像重叠如果它位于较低的单元格以下,则更好。

第一比例填充第二比例 填充

在此处输入图片说明 我要使用纵横比填充和增益,如下所示:

在此处输入图片说明

我使用以下方法选择图像模式

在此处输入图片说明

我的密码

细胞

- (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;

    }

您应该尝试使用:

image.clipsToBounds = YES;
image.contentMode = UIViewContentModeScaleAspectFill;

它给您想要的结果吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM