public override void LayoutSubviews()
{
if (_Indicator == null) return;
RectangleF frame = Bounds;
// Compute HUD dimensions based on indicator size (add margin to HUD border)
RectangleF indFrame = _Indicator.Bounds;
_Width = indFrame.Size.Width + 2 * MARGIN;
_Height = indFrame.Size.Height + 2 * MARGIN;
// Position the indicator
indFrame = new RectangleF((float)Math.Floor((frame.Size.Width - indFrame.Size.Width) / 2) + _XOffset, (float)Math.Floor((frame.Size.Height - indFrame.Size.Height) / 2) + _YOffset, indFrame.Size.Width, indFrame.Size.Height);
_Indicator.Frame = indFrame;
// Add label if label text was set
if (null != TitleText)
{
// Get size of label text
SizeF dims = StringSize(TitleText, 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 = TitleFont;
_Label.AdjustsFontSizeToFitWidth = false;
_Label.TextAlignment = UITextAlignment.Center;
_Label.LineBreakMode = UILineBreakMode.WordWrap;
_Label.Opaque = false;
_Label.BackgroundColor = UIColor.Clear;
_Label.TextColor = UIColor.White;
_Label.Text = TitleText;
// Update HUD size
if (_Width < (lWidth + 2 * MARGIN))
{
_Width = lWidth + 2 * MARGIN;
}
//Set number of lines for the amount of text and re-adjust height
_Label.Lines = (int)(dims.Width / lWidth) + 1;
if (dims.Width % lWidth == 0)
_Label.Lines--;
lHeight = lHeight * _Label.Lines;
// 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;
_Height = _Height + lHeight + PADDING;
AddSubview(_Label);
// Add details label delatils text was set
if (null != DetailText)
{
// Get size of label text
dims = StringSize(DetailText, 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 = DetailFont;
_DetailsLabel.AdjustsFontSizeToFitWidth = false;
_DetailsLabel.TextAlignment = UITextAlignment.Center;
_DetailsLabel.LineBreakMode = UILineBreakMode.WordWrap;
_DetailsLabel.Opaque = false;
_DetailsLabel.BackgroundColor = UIColor.Clear;
_DetailsLabel.TextColor = UIColor.White;
_DetailsLabel.Text = DetailText;
// Update HUD size
if (_Width < lWidth)
{
_Width = lWidth + 2 * MARGIN;
}
//Set number of lines for the amount of text and re-adjust height
_DetailsLabel.Lines = (int)(dims.Width / lWidth) + 1;
if (dims.Width % lWidth== 0)
_DetailsLabel.Lines--;
lHeight = lHeight * _DetailsLabel.Lines;
// 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;
_Height = _Height + lHeight + PADDING;
AddSubview(_DetailsLabel);
}
}
if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft)
Transform = CGAffineTransform.MakeRotation(ToRadians(90f));
else if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight)
Transform = CGAffineTransform.MakeRotation(ToRadians(-90f));
else if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown)
Transform = CGAffineTransform.MakeRotation(ToRadians(180f));
}