当前位置: 首页>>代码示例>>C#>>正文


C# NSString.GetBoundingRect方法代码示例

本文整理汇总了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;
              }
        }
开发者ID:anthonylowther21,项目名称:DebtCalculator,代码行数:26,代码来源:FontAwesomeImageHelper.cs

示例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 ();
            }
        }
开发者ID:readiescards,项目名称:mobile,代码行数:33,代码来源:TagChipCache.cs

示例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;
        }
开发者ID:pierceboggan,项目名称:Verses,代码行数:28,代码来源:InterfaceHelper.cs

示例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);
		}
开发者ID:Ontropix,项目名称:onliner-reader,代码行数:10,代码来源:FeedViewControllerSource.cs

示例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;
        }
开发者ID:kirtisagar,项目名称:XamarinFormsRadioButtonXAML,代码行数:12,代码来源:StringExtensions.cs

示例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;
		}
开发者ID:alexrainman,项目名称:CarouselView,代码行数:20,代码来源:TextMeterImplementation.cs

示例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;
			}
		}
开发者ID:prashantvc,项目名称:MonoTouch.Dialog,代码行数:14,代码来源:DemoOwnerDrawnElement.cs

示例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);
        }
开发者ID:rendr,项目名称:autocompletetextfield,代码行数:45,代码来源:AutocompleteTextField.cs

示例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;
		}
开发者ID:EckyZero,项目名称:Hashtagg,代码行数:28,代码来源:TableViewExtensions.cs

示例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);
		}
开发者ID:Securecom,项目名称:Securecom-Messaging-iOS,代码行数:5,代码来源:ChatBubbleCell.cs


注:本文中的NSString.GetBoundingRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。