尝试圆形图像,输出菱形?

Gre*_*osa 3 objective-c uitableview uiimageview uiimage ios

我有一个奇怪的问题.我正在解析数据并提取图像的URL,然后将其设置为单元格' imageView'.从我能理解的,我应该设置'的大小'cornerRadius '为图像高度的一半.因为我将数据拉入高度为100的表格视图单元格中,所以我将角半径设置为50.

然而,当视图加载到图像的第一个初始载荷上时,它们就像小钻石一样出现.当我旋转设备(也旋转表格视图)时,它会自动恢复全尺寸图像,也具有圆度.

这是初始加载的示例图像,

在此输入图像描述

有人知道为什么会这样吗?

这是我的tableView代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    NSDictionary *generatedUsers = [self.randomlyGeneratedUsersArray objectAtIndex:indexPath.row];
    NSURL *url = [NSURL URLWithString:[generatedUsers valueForKeyPath:@"user.picture"]];
    cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", [generatedUsers valueForKeyPath:@"user.name.first"], [generatedUsers valueForKeyPath:@"user.name.last"]];
    cell.detailTextLabel.text = [generatedUsers valueForKeyPath:@"user.location.street"];
    [cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder"]];

    cell.imageView.layer.cornerRadius = 50.0f;
    cell.imageView.layer.masksToBounds = YES;

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

Der*_*mot 6

你确定自动布局之类的东西在运行时没有改变你的imageView高度吗?尝试设置角半径,如下所示:

cell.imageView.layer.corderRadius = (cell.imageView.bounds.size.height /2);
//And to try figure out what's going on...
NSLog(@"Cell imageview height: %f",cell.imageView.bounds.size.height);
Run Code Online (Sandbox Code Playgroud)

  • +1只是发布相同,你打败我所以没有发布.干杯. (3认同)