0

摘要概述

我的 UITableViewSource 中有以下覆盖 GetCell。一切正常,但我想让单元格左侧的图像更小,而不必调整它的大小。本质上,我只是想缩小框架说,(30 宽 x 30 高)....也许还有圆角(类似于 Whatsapp 的打开聊天列表)。

问题

简单地将新的 RectangleF 应用于 ImageView 的 Frame 属性似乎不起作用。

 if (tableItems[indexPath.Section].Items[indexPath.Row].ImageName != null)
                                {
//RESIZE IMAGE VIEW
cell.ImageView.Frame = new RectangleF(5,5,30,30);
                                        Console.WriteLine("Image name: " + tableItems[indexPath.Section].Items[indexPath.Row].ImageName);
                                        cell.ImageView.Image = UIImage.FromFile (tableItems[indexPath.Section].Items[indexPath.Row].Image); 
                                }

代码

 public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
            {
                    UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
                    Custom_UITableItem item = tableItems[indexPath.Section].Items[indexPath.Row];
                    var cellStyle = UITableViewCellStyle.Subtitle;

                    // if there are no cells to reuse, create a new one
                    if (cell == null) 
                    {
                            cell = new UITableViewCell (cellStyle, cellIdentifier);
                    }

                    try
                    {
                            if(cellAccessoryButtons.Count > 0)
                            {
                                    var cellAccessoryButton = cellAccessoryButtons [indexPath.Row];
                                    cell.AccessoryView = cellAccessoryButton;
                            }

                            cell.TextLabel.Text = tableItems[indexPath.Section].Items[indexPath.Row].Heading;
                            cell.TextLabel.Font = AppSettings.CellDetailTextLabelFontSize;
                            cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                            cell.TextLabel.Lines = 2;
                            cell.DetailTextLabel.Text = tableItems[indexPath.Section].Items[indexPath.Row].SubHeading;
                            cell.DetailTextLabel.Font = AppSettings.CellDetailTextLabelFontSize;
                            cell.DetailTextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                            cell.DetailTextLabel.Lines = 2;

                            if (tableItems[indexPath.Section].Items[indexPath.Row].ImageName != null)
                            {
//RESIZE IMAGE VIEW
cell.ImageView.Frame = new RectangleF(5,5,30,30);

                                    Console.WriteLine("Image name: " + tableItems[indexPath.Section].Items[indexPath.Row].ImageName);
                                    cell.ImageView.Image = UIImage.FromFile (tableItems[indexPath.Section].Items[indexPath.Row].Image); 
                            }

                            var trackUploadedDateFrame = new RectangleF (87, 55, 100, 20);
                            var trackUploadedDate = new UILabel (trackUploadedDateFrame);
                            trackUploadedDate.BackgroundColor = UIColor.Clear;
                            trackUploadedDate.Font = AppSettings.TrackUploadedDateFontSize;
                            trackUploadedDate.TextAlignment = UITextAlignment.Left;
                            trackUploadedDate.Text = "Uploaded: 16/10/13";
                            cell.AddSubview (trackUploadedDate);

                    }
                    catch(Exception ex) 
                    {
                            Console.WriteLine (ex.ToString ());
                    }

                    return cell;
            } 
4

2 回答 2

1

简而言之,“去过那里,做到了”,让我告诉你自定义库存 UITableViewCell - 特别是它的 ImageView 是一种皇家痛苦。

根据我的经验,通过继承 UITableViewCell 更容易实现您的设计目标 - 无论是在代码中还是使用 IB 的 .xib 中 - 除非股票 UITableViewCell 的功能非常接近您自己的目标。

于 2013-10-24T13:06:43.780 回答
0

使用以下函数调整图像大小,然后将其设置为表格单元格图像视图

 public UIImage ResizeImage(UIImage sourceImage, float width, float height)
        {
            UIGraphics.BeginImageContext(new SizeF(width, height));
            sourceImage.Draw(new RectangleF(0, 0, width, height));
            var resultImage = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();
            return resultImage;
        }
于 2018-05-14T14:38:36.437 回答