本文整理汇总了C#中NSString.GetBoundingRect方法的典型用法代码示例。如果您正苦于以下问题:C# NSString.GetBoundingRect方法的具体用法?C# NSString.GetBoundingRect怎么用?C# NSString.GetBoundingRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NSString
的用法示例。
在下文中一共展示了NSString.GetBoundingRect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFontSize
private static void GetFontSize(UILabel label, CGSize size, int maxFontSize, int minFontSize)
{
label.Frame = new CGRect(CGPoint.Empty, size);
var fontSize = maxFontSize;
var constraintSize = new CGSize(label.Frame.Width, nfloat.MaxValue);
while (fontSize > minFontSize)
{
label.Font = UIFont.FromName(label.Font.Name, fontSize);
using (var nativeString = new NSString(label.Text))
{
var textRect = nativeString.GetBoundingRect(
constraintSize,
NSStringDrawingOptions.UsesFontLeading,
new UIStringAttributes { Font = label.Font},
null
);
if (textRect.Size.Height <= label.Frame.Height)
{
break;
}
}
fontSize -= 2;
}
}
示例2: CreateImage
private UIImage CreateImage (NSString title, float scale)
{
var titleAttrs = new UIStringAttributes () {
Font = UIFont.FromName ("HelveticaNeue", 13f),
ForegroundColor = Color.Gray,
};
var titleBounds = title.GetBoundingRect (
new SizeF (Single.PositiveInfinity, Single.PositiveInfinity),
NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesDeviceMetrics,
titleAttrs,
null);
var image = Image.TagBackground;
var imageBounds = new RectangleF (
0, 0,
(float)Math.Ceiling (titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f,
(float)Math.Ceiling (titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom
);
titleBounds.X = image.CapInsets.Left + 2f;
titleBounds.Y = image.CapInsets.Top;
UIGraphics.BeginImageContextWithOptions (imageBounds.Size, false, scale);
try {
image.Draw (imageBounds);
title.DrawString (titleBounds, titleAttrs);
return UIGraphics.GetImageFromCurrentImageContext ();
} finally {
UIGraphics.EndImageContext ();
}
}
示例3: ContentSize
public static float ContentSize(UITextView textView)
{
var frame = textView.Bounds;
var textContainerInsets = textView.TextContainerInset;
var contentInsents = textView.ContentInset;
var leftRightPadding = textContainerInsets.Left + textContainerInsets.Right + textView.TextContainer.LineFragmentPadding * 2 + contentInsents.Left + contentInsents.Right;
var topBottomPadding = textContainerInsets.Top + textContainerInsets.Bottom + contentInsents.Top + contentInsents.Bottom;
var width = frame.Size.Width;
width -= leftRightPadding;
var height = frame.Size.Height;
height -= topBottomPadding;
frame.Size = new SizeF (width, height);
var text = new NSString (textView.Text);
var attributes = new UIStringAttributes {
Font = textView.Font
};
var size = text.GetBoundingRect (new SizeF (frame.Width, float.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, new NSStringDrawingContext ());
float measuredHeight = size.Height + topBottomPadding;
return measuredHeight;
}
示例4: GetHeightForRow
public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
{
FeedItem comment = FeedItems [indexPath.Item];
NSString caption = new NSString (comment.Caption);
RectangleF rect = caption.GetBoundingRect (new SizeF (150, 0), NSStringDrawingOptions.UsesLineFragmentOrigin,
new UIStringAttributes () { }, null);
return Math.Max (55, rect.Height);
}
示例5: StringHeight
public static float StringHeight(this string text, UIFont font, float width)
{
var nativeString = new NSString(text);
var rect = nativeString.GetBoundingRect(
new System.Drawing.SizeF(width, float.MaxValue),
NSStringDrawingOptions.UsesLineFragmentOrigin,
new UIStringAttributes() { Font = font },
null);
return rect.Height;
}
示例6: MeasureTextSize
public double MeasureTextSize(string text, double width, double fontSize, string fontName = null)
{
var nsText = new NSString(text);
var boundSize = new SizeF((float)width, float.MaxValue);
var options = NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin;
if (fontName == null)
{
fontName = "HelveticaNeue";
}
var attributes = new UIStringAttributes
{
Font = UIFont.FromName(fontName, (float)fontSize)
};
var sizeF = nsText.GetBoundingRect(boundSize, options, attributes, null).Size;
return (double)sizeF.Height + 5;
}
示例7: TextHeight
private nfloat TextHeight (RectangleF bounds)
{
using (NSString str = new NSString (this.Subject))
{
return str.GetBoundingRect (new SizeF (bounds.Width - 20, 1000), NSStringDrawingOptions.UsesLineFragmentOrigin, new UIStringAttributes ()
{
Font = subjectFont,
ParagraphStyle = new NSMutableParagraphStyle ()
{
LineBreakMode = UILineBreakMode.WordWrap,
},
}, null).Height;
}
}
示例8: AutoCompleteRectForBounds
private CGRect AutoCompleteRectForBounds(CGRect bounds)
{
// get bounds for whole text area
CGRect textRectBounds = this.TextRect(bounds);
if (this.BeginningOfDocument == null)
return CGRect.Empty;
// get rect for actual text
UITextRange textRange = this.GetTextRange(this.BeginningOfDocument, this.EndOfDocument);
CGRect textRect = this.GetFirstRectForRange(textRange).Integral();
NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle();
paragraphStyle.LineBreakMode = UILineBreakMode.CharacterWrap;
NSString text = new NSString(this.Text);
UIStringAttributes attributes = new UIStringAttributes();
attributes.Font = this.Font;
attributes.ParagraphStyle = paragraphStyle;
CGRect prefixTextRect = text.GetBoundingRect(
textRect.Size,
NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading,
attributes, null
);
CGSize prefixTextSize = prefixTextRect.Size;
NSString str = new NSString(autocompleteString);
CGRect autocompleteTextRect = str.GetBoundingRect(
new CGSize(textRectBounds.Size.Width - prefixTextSize.Width, textRectBounds.Size.Height),
NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading,
attributes, null
);
CGSize autocompleteTextSize = autocompleteTextRect.Size;
return new CGRect(textRect.GetMaxX() + 6, //6 - correction
textRectBounds.GetMinY() - 1, //1 - correction
autocompleteTextSize.Width,
textRectBounds.Size.Height);
}
示例9: SizeHeaderToFitLabels
public static void SizeHeaderToFitLabels(this UITableView tableView, List<UILabel> labels, bool ignoreNewLineCharacters = true, float offset = 0f)
{
var currentFrame = tableView.TableHeaderView.Frame;
nfloat sumHeight = 0f;
foreach (UILabel label in labels)
{
label.Text = FormatString (ignoreNewLineCharacters, label.Text);
var nstext = new NSString (label.Text);
var firstAttributes = new UIStringAttributes {
Font = label.Font,
};
var temp = nstext.GetBoundingRect (new CGSize (label.Frame.Width, 0), NSStringDrawingOptions.UsesLineFragmentOrigin, firstAttributes, null);
sumHeight += temp.Height;
}
var viewsThatAreAlighedToTheLeftOfTheScreen = tableView.TableHeaderView.Subviews.Where (v=> v.Frame.Left <= (tableView.TableHeaderView.Frame.GetMidX()/2f)).OrderBy(v=> v.Frame.Top).ToList();
var otherViews = viewsThatAreAlighedToTheLeftOfTheScreen.Where(v=> !labels.Contains(v)).ToList();
var otherViewsHeight = otherViews.Sum (v => v.Frame.Height);
var spacing = currentFrame.Height - (viewsThatAreAlighedToTheLeftOfTheScreen.Sum(v=> v.Frame.Height));
var finalHeight = (float) ((double)spacing + otherViewsHeight + (double)sumHeight) + offset;
currentFrame.Height = finalHeight;
tableView.TableHeaderView.Frame = currentFrame;
}
示例10: GetSizeForText
SizeF GetSizeForText (UIView tv, string text, bool splitLine){
NSString nsText = new NSString (text);
var textRect = nsText.GetBoundingRect (new SizeF (tv.Bounds.Width * .9f - 10 - 22, 99999), (splitLine ? NSStringDrawingOptions.UsesLineFragmentOrigin : 0), new UIStringAttributes { Font = font }, new NSStringDrawingContext ());
return new SizeF (textRect.Width, textRect.Height);
}