[英]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.