Hi,
My app generates a custom button on the fly like this
var button = UICreation.CreateLongVeryThinButton(new PointF(x, y), filename, padName.paddockname + " (" + total.ToString() + ")", p, false);
button.TouchUpInside += HandleMobSummary;
buttons.Add(button); // list required to stop the GC eating the button
y += 56;
scrollView.AddSubview(button);
public static UIButton CreateLongVeryThinButton(PointF where, string filename, string text1, string tag = "", bool makeBold = false)
{
var posn = new RectangleF(where.X, where.Y, AppDelegate.Self.ScreenX - 10, 50);
if (!CheckFile(filename))
{
#if DEBUG
Console.WriteLine("Filename failed : {0}", filename);
#endif
filename = "Graphics/Weather/dunno.png";
}
var theButton = new UIButton(UIButtonType.Custom)
{
Frame = posn,
BackgroundColor = UIColor.LightGray,
AccessibilityLabel = tag
};
var image = new UIImageView();
image.Frame = new RectangleF(4, 4, 36, 36);
image.Image = UIImage.FromFile(filename).Scale(new SizeF(36, 36), AppDelegate.Self.Retina ? 2 : 1);
var topLabel = new UILabel(new RectangleF(80, 12, 206, 25))
{
Text = text1,
TextColor = UIColor.Black,
Font = !makeBold ? UIFont.SystemFontOfSize(17f) : UIFont.BoldSystemFontOfSize(17f),
AdjustsFontSizeToFitWidth = true,
BackgroundColor = UIColor.LightGray
};
theButton.AddSubviews(new UIView[]{ image, topLabel });
return theButton;
}
The code works fine and generates the button I need. Problem is that with a large number of buttons being created, there is a huge slowdown of the UI.
Is there a way to speed this so that it is not hugely different to a normal UI with (say) 100 buttons on it being rendered?
Paul