简体   繁体   English

正确使用iOS Xcode中的宽高比

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

Aspect ratio "Scale To Fill" and "Aspect Fit" make the image stretched to whole UIImageView size. 纵横比“缩放以填充”“纵横比匹配”使图像拉伸到整个UIImageView大小。 How can I use Aspect Fill" to handell UIImageView inside UITableViewCell. UIImageView inside UITableViewCell is running out of the screen in Aspect Fill . I want to make the image to take is original size rather then to stretch but I want to prevent it form overlapping over its lower cell. Rather its better if it goes below the lower cell. 如何使用Aspect Fill”来处理UITableViewCell内的UIImageView。UITableViewCell内的UIImageView在Aspect Fill中用尽了屏幕。我想使图像采用原始大小,而不是拉伸,但我想防止图像重叠如果它位于较低的单元格以下,则更好。

First Scale To Fill Second Aspect Fill 第一比例填充第二比例 填充

在此处输入图片说明 I want to use Aspect Fill and gain as below: 我要使用纵横比填充和增益,如下所示:

在此处输入图片说明

I use following to select the image mode 我使用以下方法选择图像模式

在此处输入图片说明

My code 我的密码

Cell.m 细胞

- (void)awakeFromNib {
     _img.clipsToBounds = YES;
    _img.contentMode = UIViewContentModeScaleAspectFill;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
  }

VCUIViewController.m 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;

    }

You should try to use: 您应该尝试使用:

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

Does it give you the desired results? 它给您想要的结果吗?

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

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