私はこの所有者が要素を描いています:
using System;
using Tracktion.Service.WCF.Entities;
using MonoTouch.Dialog;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using System.Drawing;
using MonoTouch.Foundation;
namespace Tracktion.iOS
{
public class EventListingElement : OwnerDrawnElement
{
public static UIFont EventTitleFont = UIFont.BoldSystemFontOfSize (18f);
public static UIFont EventTypeFont = UIFont.SystemFontOfSize (14f);
public static UIFont CountsFont = UIFont.ItalicSystemFontOfSize (14f);
public static UIFont DatesFont = UIFont.SystemFontOfSize (14f);
public static UIColor DefaultBackgroundColor = UIColor.White;
public EventListingElement (EventListingItem item) : base(UITableViewCellStyle.Default, "EventListingElement")
{
ev = item;
}
public EventListingElement (EventListingItem item, Action<EventListingItem> tapped) : this(item)
{
whenTapped = tapped;
}
EventListingItem ev;
Action<EventListingItem> whenTapped = null;
public override void Draw (RectangleF bounds, CGContext context, UIView view)
{
//view.BackgroundColor = EventListingElement.DefaultBackgroundColor;
//CGContext currentContext = UIGraphics.GetCurrentContext ();
SizeF sizeF;
float num = 0f;
UIColor.FromRGB (36, 112, 216).SetColor ();
string dateStr;
if (ev.StartTime.HasValue)
{
TimeSpan t = DateTime.Now - ev.StartTime.Value;
if (DateTime.Now.Day == ev.StartTime.Value.Day)
{
dateStr = ev.StartTime.Value.ToShortTimeString ();
}
else
{
if (t <= TimeSpan.FromHours (24.0))
{
dateStr = "Yesterday"; //.GetText ();
}
else
{
if (t < TimeSpan.FromDays (6.0))
{
dateStr = ev.StartTime.Value.ToString ("dddd");
}
else
{
dateStr = ev.StartTime.Value.ToShortDateString ();
}
}
}
}
else
{
dateStr = "Date TBA";
}
// Setup counts
string counts = "Staff & Volunteers: {0} reg, {1} in, {2} out\n";
counts += "Students & Visitors: {3} reg, {4} in, {5} out";
counts = string.Format (counts, ev.CountOfStaffAndVolunteersRegistered, ev.CountOfStaffAndVolunteersCheckedIn, ev.CountOfStaffAndVolunteersCheckedOut, ev.CountOfStudentsAndVisitorsRegistered, ev.CountOfStudentsAndVisitorsCheckedIn, ev.CountOfStudentsAndVisitorsCheckedOut);
float left = 13f;
// Draw
sizeF = view.StringSize (dateStr, EventListingElement.EventTitleFont);
float num2 = sizeF.Width + 21f + 5f;
RectangleF dateFrame = new RectangleF (view.Bounds.Width - num2, 6f, num2, 14f);
/*if (ev.StartTime != null && ev.StartTime.Value.Date == DateTime.Today)
{
currentContext.SaveState ();
currentContext.AddEllipseInRect (dateFrame);
currentContext.Clip ();
currentContext.DrawLinearGradient (EventListingElement.EventIsTodayGradient, new PointF (10f, 32f), new PointF (22f, 44f), CGGradientDrawingOptions.DrawsAfterEndLocation);
currentContext.RestoreState ();
}*/
view.DrawString (dateStr, dateFrame, EventListingElement.DatesFont, UILineBreakMode.Clip, UITextAlignment.Left);
float num3 = view.Bounds.Width - left;
UIColor.Black.SetColor ();
if (!string.IsNullOrWhiteSpace (ev.EventType))
{
view.DrawString (ev.EventType, new PointF (left, 2f), num3 - num2, EventListingElement.EventTypeFont, UILineBreakMode.TailTruncation);
}
view.DrawString (ev.Name, new PointF (left, 23f), num3 - left - num, EventListingElement.EventTitleFont, UILineBreakMode.TailTruncation);
UIColor.Gray.SetColor ();
view.DrawString (counts, new RectangleF (left, 40f, num3 - num, 34f), EventListingElement.CountsFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
/*if (this.NewFlag)
{
currentContext.SaveState ();
currentContext.AddEllipseInRect (new RectangleF (10f, 32f, 12f, 12f));
currentContext.Clip ();
currentContext.DrawLinearGradient (MessageSummaryView.gradient, new PointF (10f, 32f), new PointF (22f, 44f), CGGradientDrawingOptions.DrawsAfterEndLocation);
currentContext.RestoreState ();
}
*/
UIColor.Clear.SetFill();
UIColor.Black.SetColor ();
}
public override UITableViewCell GetCell (UITableView tv)
{
var cell = base.GetCell (tv);
cell.BackgroundColor = UIColor.Clear;
cell.BackgroundView = new UIView(RectangleF.Empty) { BackgroundColor = UIColor.Clear };
cell.SetNeedsDisplay();
return cell;
}
public override float Height (RectangleF bounds)
{
return 90f;
}
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
base.Selected (dvc, tableView, path);
if (whenTapped != null)
whenTapped(this.ev);
}
}
}
大きな問題が発生しているため、すべてを正しくレイアウトしていません。最初は常に背景が黒くなり、角が丸くなりません。ただし、セルを選択した後、および選択を解除した後、セルは細かく、角が丸く、すべてに見えます。私が何をする必要があるかについての提案はありますか?セル用とビュー用の2つの内部クラスを持つUIViewを使い始めましたが、同じ運があり、OwnerDrawnElementに切り替えるとこれが修正されると思いました。