我正在创建一个基于 Monotouch 元素的元素。这样做的结果是创建一个列表(如 Twitter 时间线),每个单元格中都有主题、域名和 Fav-Icon。问题是这样的:列表的第一个和最后一个收藏图标显示了两次,因此它们彼此重叠。
下面是代码。谁能看到我犯了什么错误?/罗伯特
public override void Draw (RectangleF rect)
{
const int padright = 12;//21;
var ctx = UIGraphics.GetCurrentContext ();
bool highlighted = (Superview.Superview as UITableViewCell).Highlighted;
var bounds = Bounds;
var midx = bounds.Width/2;
if (highlighted){
UIColor.FromRGB (4, 0x79, 0xef).SetColor ();
ctx.FillRect (bounds);
//Images.MenuShadow.Draw (bounds, CGBlendMode.Normal, 0.5f);
//textColor = UIColor.White;
} else {
UIColor.White.SetColor ();
ctx.FillRect (bounds);
ctx.DrawLinearGradient (bottomGradient, new PointF (midx, bounds.Height-17), new PointF (midx, bounds.Height), 0);
ctx.DrawLinearGradient (topGradient, new PointF (midx, 1), new PointF (midx, 3), 0);
}
float boxWidth;
float boxHeight = Bounds.Height;
boxWidth = 0;
//SizeF ssize;
//string label;
//label = Date;
//ssize = StringSize (label, SubjectFont);
//float dateSize = ssize.Width + padright + 5;
//DrawString (label, new RectangleF (Bounds.Width-dateSize-5, 5, dateSize, 14), DateFont, UILineBreakMode.Clip, UITextAlignment.Right);
const int offset = 46; //33;
float bw = Bounds.Width-offset;
UIColor.Black.SetColor ();
//Extracting the domain name that I get.
string domainName = new Uri(Sender).DnsSafeHost;
if(domainName.StartsWith("www"))
{
domainName = domainName.Substring(4, domainName.Length-4);
}
//Checking to see if there is any subdomain.
//If so, I start at the first dot to get the domainname "clean".
int countDots = domainName.Split('.').Length - 1;
if(countDots > 1)
{
Console.WriteLine("Dots: " + countDots);
int i = domainName.IndexOf('.') + 1;
Console.WriteLine("Position: " + i);
domainName = domainName.Substring(i).Trim();
Console.WriteLine("Domain: " + domainName);
}
DrawString (Subject, new RectangleF (offset, 6, bw-boxWidth-5, 24), SubjectFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
DrawString (domainName, new PointF (offset, 28), bw/*-dateSize*/, SenderFont, UILineBreakMode.TailTruncation);
//Getting the fav icon from the domainname and posting it to g.etfv.co.
string favUrl = "http://www."+domainName;
Console.WriteLine("Fav icon: " + favUrl);
Uri imageBackground = null;
imageBackground = new Uri ("http://g.etfv.co/"+ favUrl);
var avatar = ImageLoader.DefaultRequestImage (imageBackground, this);
var imageRect = new RectangleF(15f, 10f, 16f, 16f);
using (var myImage = new UIImageView(imageRect))
{
if(avatar == null)
{
//A local avatar if something goes wrong
string localAvatar = "Images/avatar.png";
myImage.Image = UIImage.FromFile(localAvatar);
}
else
{myImage.Image = avatar;}
AddSubview(myImage);
}
avatar = null;
}