最初加载UITableView时,滚动后的圆形imageview角半径会发生变化-Xamarin.iOS

时间:2019-06-04 10:14:51

标签: uitableview xamarin.ios uiimageview

我想在我的UIImageView中制作UITableViewCell。这是我的代码

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
       RemoteSupportTableViewCell cell = (RemoteSupportTableViewCell)tableView.DequeueReusableCell(_cellIdentifier);
       RemotesupportAgentData item = _tableItems[indexPath.Row];

        cell.TextLabel.Text = (string)item.Attributes["Name"];
        cell.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
        UIImageView tempImageView = new UIImageView();
        tempImageView.SetImage(new NSUrl((string)item.Attributes["avatar"]), UIImage.FromBundle("contacts-32.png"));
        cell.ImageView.Image = MaxResizeImage(tempImageView.Image, 50, 50);
        CGRect imgvwFrame = cell.ImageView.Frame;
        imgvwFrame.Height = 50;
        imgvwFrame.Width = 50;
        cell.ImageView.Frame = imgvwFrame;
        cell.LayoutIfNeeded();

        return cell;
    }

在我的自定义单元格中

 public RemoteSupportTableViewCell(IntPtr handle)
        : base(handle)
    {
        SelectionStyle = UITableViewCellSelectionStyle.None;
        ImageView.ClipsToBounds = true;
        ImageView.Layer.MasksToBounds = true;
        ImageView.Layer.BorderColor = UIColor.Green.CGColor;
        ImageView.Layer.BorderWidth = (nfloat)2.0;
    }

    public override void Draw(CGRect rect)
    {
        base.Draw(rect);

        // Your will get the actual size in the event
        if (ImageView.Layer.CornerRadius == 0)
            ImageView.Layer.CornerRadius = ImageView.Frame.Width / 2;
    }

最初加载UI时,我可以在每个单元格图像中看到占位符图像,它们是圆圈。当我滚动表格视图时,它开始从url加载图像并替换占位符图像。但是我的问题是,当它从url加载图像时,这些图像不是完美的圆圈。但是如果我返回上一个ViewController并返回,则可以看到所有已加载网址的图片都放置在完美的圆圈内。

最初加载表格视图时会发生什么?我该如何克服呢? 谢谢

0 个答案:

没有答案