我将图像视图大小设置为固定。我在故事栏中设置了约束,约束是正确的。但是当我从Web服务加载一些图像后,当我点击单元格时,一些图像改变了它的大小,其中一些没有。我已将图像视图contentMode设置为纵横拟合。如何使图像自动调整大小以适应图像视图,我不必单击单元格,使其调整大小以适应?
cellForRow:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
LocalCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell) {
cell = [[LocalCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *photoReference = [self.restaurants[indexPath.row][@"photos"] objectAtIndex:0][@"photo_reference"];
NSString *photo = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/photo?maxwidth=80&photoreference=%@&sensor=true&key=%@", photoReference, AppKey];
cell.name.text = self.restaurants[indexPath.row][@"name"];
cell.desc.text = self.restaurants[indexPath.row][@"vicinity"];
[cell.imageView setImageWithURL:[NSURL URLWithString:photo] placeholderImage:[UIImage imageNamed:@"placeholder"]];
return cell;
}
答案 0 :(得分:0)
将您的UIImageView clipsToBounds 设置为 YES ,如下所示
[yourImageView clipsToBounds:YES];
答案 1 :(得分:0)
我刚想通了:
- (void)layoutSubviews
{
[super layoutSubviews];
self.imageView.frame = CGRectMake(15, 15, 80, 50);
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
}