摘要概述
我的 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;
}