本文整理汇总了C#中UILabel.SizeThatFits方法的典型用法代码示例。如果您正苦于以下问题:C# UILabel.SizeThatFits方法的具体用法?C# UILabel.SizeThatFits怎么用?C# UILabel.SizeThatFits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UILabel
的用法示例。
在下文中一共展示了UILabel.SizeThatFits方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSectionHeader
public void AddSectionHeader(string name)
{
UILabel label = new UILabel();
label.Text = name.ToUpperInvariant();
label.Font = Application.ThemeColors.HeaderFont;
label.TextColor = Application.ThemeColors.Main;
var y = _container.Subviews.Length == 0 ? _padding : _container.Subviews.Last().Frame.Bottom + _padding;
label.Frame = new RectangleF(_padding, y, _boxWidthMinusPadding, label.SizeThatFits(new SizeF(_boxWidthMinusPadding, 0)).Height);
_container.Add(label);
}
示例2: NativeMeasureContent
protected virtual CGSize NativeMeasureContent(CGSize availableSize)
{
if (this.contentTemplateInstance != null)
{
return this.contentTemplateInstance.MeasureOverride(availableSize);
}
var uiContent = this.Content as UIElement;
if (uiContent != null)
{
return uiContent.MeasureOverride(availableSize);
}
if (this.textContent != null)
{
return this.textContent.MeasureOverride(availableSize);
}
var stringContent = this.Content == null ? "" : this.Content.ToString();
var label = new UILabel();
label.Text = stringContent;
return label.SizeThatFits(availableSize);
}
示例3: CreateBox
UIView CreateBox(float x, float y, float width, float height, string itemChar)
{
var item = ViewModel.ListElements.First(l => l.IconChar == itemChar);
UIView view = new UIView(new RectangleF(0,0, width, height));
view.Center = new PointF(x + width / 2, y + height / 2);
view.AddGestureRecognizer(new BoxGestureRecognizer(view));
view.AddGestureRecognizer(new UITapGestureRecognizer(() => item.GoToCommand.Execute(null)));
view.BackgroundColor = ColorFor(item);
UILabel title = new UILabel();
title.TextColor = UIColor.White;
title.BackgroundColor = UIColor.Clear;
if (height < 120) title.Font = Application.ThemeColors.DefaultFont.WithSize(12f);
else if (height < 200) title.Font = Application.ThemeColors.DefaultFont;
else title.Font = Application.ThemeColors.TitleFont.WithSize(20f);
title.Text = item.Title;
var size = title.SizeThatFits(new SizeF(width, 0));
var titleX = (width-size.Width) / 2;
var titleY = height-size.Height-5f;
title.Frame = new RectangleF(new PointF(titleX,titleY), size);
view.Add(title);
var icon = new UILabel();
icon.BackgroundColor = UIColor.Clear;
icon.Font = Application.ThemeColors.IconFont.WithSize(height / 3);
var heightOffset = height < 200 ? -3 : 0;
icon.TextColor = UIColor.White;
icon.TextAlignment = UITextAlignment.Center;
icon.LineBreakMode = UILineBreakMode.CharacterWrap;
icon.Frame = new RectangleF(0,0, height - 40, height - 40);
icon.Center = new PointF(width / 2, (height / 2)+heightOffset);
icon.Text = item.IconChar;
view.Add(icon);
return view;
}
示例4: SizeThatFitsWidth
private static CGSize SizeThatFitsWidth(UILabel label, nfloat width)
{
var font = label.Font;
return label.SizeThatFits(new CGSize(width, font.LineHeight * label.Lines));
}
示例5: UpdateProgressViewSizeForLabel
public void UpdateProgressViewSizeForLabel(UILabel label)
{
if (Progress < 1)
{
var size = label.SizeThatFits(label.Frame.Size);
var width = size.Width*(float) (1 - Progress);
var x = label.Center.X + size.Width/2f - width;
// if we werent able to determine a size, do falsething
if (size.Width == 0f)
{
return;
}
// progressView always covers only the visible portion of the text
// it "shrinks" to the right with increased progress to reveal more
// text under it
ProgressView.Hidden = false;
//[UIView animateWithDuration:progress > 0.0 ? kUpdateProgressViewDuration : 0.0
// animations:^{
ProgressView.Frame = new RectangleF(x, ProgressView.Frame.Location.Y, //origin.y,
BackgroundView.Frame.Size.Width - x, ProgressView.Frame.Size.Height);
}
else
{
ProgressView.Hidden = true;
}
}
示例6: CreateView
void CreateView ()
{
string saveInput = null;
// If input, than safe text for later use
if (input != null && inputView != null)
saveInput = inputView.Text;
// Remove all existing subviews
foreach (UIView view in this.View.Subviews) {
view.RemoveFromSuperview();
}
// Now create and add all other views
float frame = 10;
float maxWidth = this.View.Bounds.Width - 2 * frame;
float maxHeight = this.View.Bounds.Height;
UITextAlignment textAlign = UITextAlignment.Center;
int format = NSUserDefaults.StandardUserDefaults.IntForKey("TextAlignment");
switch (format) {
case 0:
textAlign = UITextAlignment.Center;
break;
case 1:
textAlign = UITextAlignment.Left;
break;
case 2:
textAlign = UITextAlignment.Right;
break;
}
if (image != null) {
imageView = new UIImageView (UIImage.LoadFromData (NSData.FromArray (image.Data))) {
ContentMode = UIViewContentMode.Center | UIViewContentMode.ScaleAspectFit
};
if (imageView.Image.Size.Width > maxWidth)
imageView.Bounds = new RectangleF (0, 0, maxWidth, imageView.Image.Size.Height * maxWidth / imageView.Image.Size.Width);
else
imageView.Bounds = new RectangleF (0, 0, maxWidth, imageView.Image.Size.Height);
// imageView.Bounds = new RectangleF (0, 0, maxWidth, imageView.Bounds.Height);
} else {
imageView = null;
}
if (!String.IsNullOrEmpty (text)) {
textView = new UILabel () {
Text = text,
BackgroundColor = UIColor.Clear,
Lines = 0,
LineBreakMode = UILineBreakMode.WordWrap,
TextAlignment = textAlign,
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
ContentMode = UIViewContentMode.Center
};
SizeF size = textView.SizeThatFits (new SizeF (maxWidth, 999999));
textView.Bounds = new RectangleF (0, 0, maxWidth, size.Height);
} else {
textView = null;
}
if (input != null && input.InputType == InputType.Text) {
inputView = new UITextField (new RectangleF (frame, maxHeight - (buttons.Count + 1) * 45, maxWidth, 35)) {
BorderStyle = UITextBorderStyle.RoundedRect,
ReturnKeyType = UIReturnKeyType.Done
};
inputView.ShouldReturn += inputShouldReturn;
if (!String.IsNullOrEmpty(saveInput))
inputView.Text = saveInput;
} else {
inputView = null;
}
buttonView = new UIView (){
ContentMode = UIViewContentMode.Center
};
if (buttons != null && buttons.Count > 0) {
buttonView.Bounds = new RectangleF (0, 0, maxWidth, buttons.Count * 45);
buttonView.BackgroundColor = UIColor.Clear;
int pos = 0;
foreach (string s in buttons) {
UIButton button = UIButton.FromType (UIButtonType.RoundedRect);
button.Tag = pos;
button.Bounds = new RectangleF (0, 0, maxWidth, 35);
button.Frame = new RectangleF (0, pos * 45, maxWidth, 35);
button.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
button.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
button.SetTitleColor(Colors.ButtonText,UIControlState.Normal);
button.SetBackgroundImage(Images.BlueButton, UIControlState.Normal);
button.SetBackgroundImage(Images.BlueButtonHighlight, UIControlState.Highlighted);
button.SetTitle (s, UIControlState.Normal);
button.TouchUpInside += OnTouchUpInside;
buttonView.AddSubview (button);
buttonViews.Add (button);
pos++;
}
} else {
buttonView = null;
}
// Create scroll view, which holds all other views
//.........这里部分代码省略.........