public override void LayoutSubviews ()
{
RectangleF frame = this.Bounds;
// Compute HUD dimensions based on indicator size (add margin to HUD border)
RectangleF indFrame = Indicator.Bounds;
this.Width = indFrame.Size.Width + 2 * MARGIN;
this.Height = indFrame.Size.Height + 2 * MARGIN;
// Position the indicator
indFrame = new RectangleF ((float)Math.Floor ((frame.Size.Width - indFrame.Size.Width) / 2) + this.XOffset, (float)Math.Floor ((frame.Size.Height - indFrame.Size.Height) / 2) + this.YOffset, indFrame.Size.Width, indFrame.Size.Height);
Indicator.Frame = indFrame;
// Add label if label text was set
if (null != this.TitleText) {
// Get size of label text
SizeF dims = StringSize (TitleText, this.TitleFont);
// Compute label dimensions based on font metrics if size is larger than max then clip the label width
float lHeight = dims.Height;
float lWidth;
if (dims.Width <= (frame.Size.Width - 2 * MARGIN)) {
lWidth = dims.Width;
} else {
lWidth = frame.Size.Width - 4 * MARGIN;
}
// Set label properties
Label.Font = this.TitleFont;
Label.AdjustsFontSizeToFitWidth = false;
Label.TextAlignment = UITextAlignment.Center;
Label.Opaque = false;
Label.BackgroundColor = UIColor.Clear;
Label.TextColor = UIColor.White;
Label.Text = this.TitleText;
// Update HUD size
if (this.Width < (lWidth + 2 * MARGIN)) {
this.Width = lWidth + 2 * MARGIN;
}
this.Height = this.Height + lHeight + PADDING;
// Move indicator to make room for the label
indFrame = new RectangleF (indFrame.Location.X, indFrame.Location.Y - (float)(Math.Floor (lHeight / 2 + PADDING / 2)), indFrame.Width, indFrame.Height);
Indicator.Frame = indFrame;
// Set the label position and dimensions
RectangleF lFrame = new RectangleF ((float)Math.Floor ((frame.Size.Width - lWidth) / 2) + XOffset, (float)Math.Floor (indFrame.Location.Y + indFrame.Size.Height + PADDING), lWidth, lHeight);
Label.Frame = lFrame;
this.AddSubview (Label);
// Add details label delatils text was set
if (null != this.DetailText) {
// Get size of label text
dims = StringSize (DetailText, this.DetailFont);
// Compute label dimensions based on font metrics if size is larger than max then clip the label width
lHeight = dims.Height;
if (dims.Width <= (frame.Size.Width - 2 * MARGIN)) {
lWidth = dims.Width;
} else {
lWidth = frame.Size.Width - 4 * MARGIN;
}
// Set label properties
DetailsLabel.Font = this.DetailFont;
DetailsLabel.AdjustsFontSizeToFitWidth = false;
DetailsLabel.TextAlignment = UITextAlignment.Center;
DetailsLabel.Opaque = false;
DetailsLabel.BackgroundColor = UIColor.Clear;
DetailsLabel.TextColor = UIColor.White;
DetailsLabel.Text = this.DetailText;
// Update HUD size
if (this.Width < lWidth) {
this.Width = lWidth + 2 * MARGIN;
}
this.Height = this.Height + lHeight + PADDING;
// Move indicator to make room for the new label
indFrame = new RectangleF (indFrame.Location.X, indFrame.Location.Y - ((float)Math.Floor (lHeight / 2 + PADDING / 2)), indFrame.Width, indFrame.Height);
Indicator.Frame = indFrame;
// Move first label to make room for the new label
lFrame = new RectangleF (lFrame.Location.X, lFrame.Location.Y - ((float)Math.Floor (lHeight / 2 + PADDING / 2)), lFrame.Width, lFrame.Height);
Label.Frame = lFrame;
// Set label position and dimensions
RectangleF lFrameD = new RectangleF ((float)Math.Floor ((frame.Size.Width - lWidth) / 2) + XOffset, lFrame.Location.Y + lFrame.Size.Height + PADDING, lWidth, lHeight);
DetailsLabel.Frame = lFrameD;
this.AddSubview (DetailsLabel);
}
}
}