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


C# UILabel.StringSize方法代码示例

本文整理汇总了C#中UILabel.StringSize方法的典型用法代码示例。如果您正苦于以下问题:C# UILabel.StringSize方法的具体用法?C# UILabel.StringSize怎么用?C# UILabel.StringSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UILabel的用法示例。


在下文中一共展示了UILabel.StringSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProgressLabel

		public ProgressLabel (string text)
			: base (new RectangleF (0, 0, 200, 44))
		{
			BackgroundColor = UIColor.Clear;
			
			activity = new UIActivityIndicatorView (UIActivityIndicatorViewStyle.White) {
				Frame = new RectangleF (0, 11.5f, 21, 21),
				HidesWhenStopped = false,
				Hidden = false,
			};
			AddSubview (activity);
			
			var label = new UILabel () {
				Text = text,
				TextColor = UIColor.White,
				Font = UIFont.BoldSystemFontOfSize (20),
				BackgroundColor = UIColor.Clear,
				Frame = new RectangleF (25, 0, Frame.Width - 25, 44),
			};
			AddSubview (label);
			
			var f = Frame;
			f.Width = label.Frame.X + label.StringSize (label.Text, label.Font).Width;
			Frame = f;
		}
开发者ID:RJInfotech,项目名称:Xamarin.Social,代码行数:25,代码来源:ProgressLabel.cs

示例2: NumberOfLines

		public static int NumberOfLines(this UIFont font, string caption, float width)
		{
			using (var label = new UILabel())
			{	
				var linefeeds = caption.Count(ch => ch == '\n');
				var size = label.StringSize(caption, font);
				
				label.Lines = 1 + ((int)(size.Width / width)) + linefeeds;
				if (size.Width % width == 0)
				{
					label.Lines--;
				}

				return label.Lines;
			}
		}
开发者ID:vknair74,项目名称:MonoMobile.Views,代码行数:16,代码来源:StringExtensions.cs

示例3: CalculateSizes

 static List<WordCloudItem> CalculateSizes(List<WordCloudItem> words, RectangleF outer)
 {
     List<WordCloudItem> calculatedWords = new List<WordCloudItem>();
     foreach (WordCloudItem word in words) {
         if (!string.IsNullOrEmpty(word.word)) {
             UILabel test = new UILabel ();
             test.Font = UIFont.FromName ("Helvetica-BoldOblique", GetWordWeight(word));
             test.LineBreakMode = UILineBreakMode.WordWrap;
             test.TextAlignment = UITextAlignment.Center;
             test.Lines = 0;
             test.Text = word.word;
             SizeF size = test.StringSize (test.Text, test.Font, new SizeF (outer.Width, outer.Height));
             word.width = size.Width;
             word.height = size.Height;
             calculatedWords.Add (word);
         }
     }
     return calculatedWords;
 }
开发者ID:Skalar,项目名称:Indexer,代码行数:19,代码来源:IndexerUtils.cs

示例4: ViewDidLoad

        public async override void ViewDidLoad()
        {
            try {
                LongRunning = true;
                base.ViewDidLoad();

                AddTableHeader(InitializeHeader());

                var response = await ServiceProxy.GetUserById(_shallowUser.user_id);
                var user = response.items.First();

                AddValue1FixedRow("Reputation", user.reputation.ToString());

                if (user.age > 0)
                    AddValue1FixedRow("Age", user.age.ToString());

                AddRow(new Value1FixedRow { 
                    Text = "Questions",
                    Details = user.question_count.ToString(),
                    Accessory = UITableViewCellAccessory.DisclosureIndicator,
                    NavController = () => new QuestionsByUserController(user.user_id)
                });

                AddRow(new Value1FixedRow { 
                    Text = "Answers",
                    Details = user.answer_count.ToString(),
                    Accessory = UITableViewCellAccessory.DisclosureIndicator,
                    NavController = () => new AnswersForUserController(user.user_id)
                });

                AddRow(new DefaultFixedRow {
                    Text = "Badges",
                    IsFixed = true,
                    NavController = () => new BadgesController(user.user_id),
                    Accessory = UITableViewCellAccessory.DisclosureIndicator,
                    AfterGetCellInit = cell => {

                        float offset = 90;

                        if (user.badge_counts.silver > 999)
                            offset -= 4;

                        if (user.badge_counts.bronze > 999)
                            offset -= 4;

                        if (user.badge_counts.gold > 0) {
                            var label = new UILabel { Text = user.badge_counts.gold.ToString() };
                            var image = new UIImageView(UIImage.FromFile("badges/gold.png"));
                            cell.ContentView.Add(label);
                            cell.ContentView.Add(image);
                            label.Frame = new RectangleF(offset, 10, label.StringSize(label.Text, label.Font).Width, 24);
                            image.Frame = new RectangleF(label.Frame.X + label.Frame.Width, 10, 24, 24);
                            offset += label.Frame.Width + image.Frame.Width + 8;
                        }

                        if (user.badge_counts.silver > 0) {
                            var label = new UILabel { Text = user.badge_counts.silver.ToString() };
                            var image = new UIImageView(UIImage.FromFile("badges/silver.png"));
                            cell.ContentView.Add(label);
                            cell.ContentView.Add(image);
                            label.Frame = new RectangleF(offset, 10, label.StringSize(label.Text, label.Font).Width, 24);
                            image.Frame = new RectangleF(label.Frame.X + label.Frame.Width, 10, 24, 24);
                            offset += label.Frame.Width + image.Frame.Width + 8;
                        }

                        if (user.badge_counts.bronze > 0) {
                            var label = new UILabel { Text = user.badge_counts.bronze.ToString() };
                            var image = new UIImageView(UIImage.FromFile("badges/bronze.png"));
                            cell.ContentView.Add(label);
                            cell.ContentView.Add(image);
                            label.Frame = new RectangleF(offset, 10, label.StringSize(label.Text, label.Font).Width, 24);
                            image.Frame = new RectangleF(label.Frame.X + label.Frame.Width, 10, 24, 24);
                            offset += label.Frame.Width + image.Frame.Width + 8;
                        }
                    }
                });

                AddRow(new DefaultFixedRow { 
                    Text = "Favorites",
                    NavController = () => new FavoritesByUserController(user.user_id, true),
                    Accessory = UITableViewCellAccessory.DisclosureIndicator
                });

                AddRow(new DefaultFixedRow { 
                    Text = "Mentions",
                    NavController = () => new UserMentionsController(user),
                    Accessory = UITableViewCellAccessory.DisclosureIndicator
                });

                AddRow(new DefaultFixedRow { 
                    Text = "Top Tags",
                    NavController = () => new TopTagsForUserController(user.user_id),
                    Accessory = UITableViewCellAccessory.DisclosureIndicator
                });

                AddValue1FixedRow("Profile Created", BclEx.OffsetFromNow(user.creation_date));

                AddSubtitleFixedRow("Votes", string.Format("{0} \uD83D\uDC4D, {1} \uD83D\uDC4E", user.up_vote_count, user.down_vote_count));

                if (user.is_employee)
//.........这里部分代码省略.........
开发者ID:jivkopetiov,项目名称:StackApp,代码行数:101,代码来源:UserProfileController.cs

示例5: CreateFooterView

			private UIView CreateFooterView(UITableView tableView, string caption)
			{
				var indentation = UIDevice.CurrentDevice.GetIndentation();

				var bounds = tableView.Bounds;
				var footerLabel = new UILabel();

				footerLabel.Font = UIFont.SystemFontOfSize(15);
				var size = footerLabel.StringSize(caption, footerLabel.Font);
				var height = size.Height * (caption.Count((ch)=>ch == '\n') + 1); 
				caption = caption.Replace("\n","");
				var rect = new RectangleF(bounds.X + indentation, bounds.Y, bounds.Width - (indentation * 2), height + 10);
				
				footerLabel.Bounds = rect;
				footerLabel.BackgroundColor = UIColor.Clear;
				footerLabel.TextAlignment = UITextAlignment.Center;
				footerLabel.TextColor = UIColor.FromRGB(76, 86, 108);
				footerLabel.ShadowColor = UIColor.White;
				footerLabel.ShadowOffset = new SizeF(0, 1);
				footerLabel.Text = caption;

				return footerLabel;
			}
开发者ID:CartBlanche,项目名称:MonoMobile.MVVM,代码行数:23,代码来源:DialogViewController.cs

示例6: CreateHeaderView

			private UIView CreateHeaderView(UITableView tableView, string caption)
			{
				var indentation = UIDevice.CurrentDevice.GetIndentation();

				var headerLabel = new UILabel();

				headerLabel.Font = UIFont.BoldSystemFontOfSize(UIFont.LabelFontSize);
				var size = headerLabel.StringSize(caption, headerLabel.Font);
				
				var bounds = new RectangleF(tableView.Bounds.X, tableView.Bounds.Y, tableView.Bounds.Width, size.Height + 10);
				var frame = new RectangleF(bounds.X + indentation + 10, bounds.Y, bounds.Width - (indentation + 10), size.Height + 10);
	
				headerLabel.Bounds = bounds;
				headerLabel.Frame = frame;
				
				headerLabel.TextColor = UIColor.FromRGB(76, 86, 108);
				headerLabel.ShadowColor = UIColor.White;
				headerLabel.ShadowOffset = new SizeF(0, 1);
				headerLabel.Text = caption;
				
				var view = new UIView(bounds) { BackgroundColor = tableView.BackgroundColor };

				if (tableView.Style == UITableViewStyle.Grouped)
				{
					headerLabel.BackgroundColor = UIColor.Clear;
					view.Opaque = false;
					view.BackgroundColor = UIColor.Clear;
				}

				view.AddSubview(headerLabel);

				return view;
			}
开发者ID:CartBlanche,项目名称:MonoMobile.MVVM,代码行数:33,代码来源:DialogViewController.cs

示例7: CreateHeaderView

		private UIView CreateHeaderView(UITableView tableView, string caption)
		{
			var indentation = UIDevice.CurrentDevice.GetIndentation();
			var width = tableView.Bounds.Width - (indentation - 10);

			var headerLabel = new UILabel() { Font = UIFont.BoldSystemFontOfSize(UIFont.LabelFontSize) };

			var size = headerLabel.StringSize(caption, headerLabel.Font);
			var height = (float)(size.Height * (headerLabel.Font.NumberOfLines(caption, width) + 0.5));

			var frame = new RectangleF(tableView.Bounds.X + (indentation + 10), 0, width, height);
			
			headerLabel.Frame = frame;
			
			headerLabel.TextColor = UIColor.FromRGB(76, 86, 108);
			headerLabel.ShadowColor = UIColor.White;
			headerLabel.LineBreakMode = UILineBreakMode.WordWrap;
			headerLabel.ShadowOffset = new SizeF(0, 1);
			headerLabel.Text = caption;
			headerLabel.Lines = headerLabel.Font.NumberOfLines(caption, frame.Width);
			
			var view = new UIView(new RectangleF(0, 0, frame.Width, height));

			if (tableView.Style == UITableViewStyle.Grouped)
			{
				headerLabel.BackgroundColor = UIColor.Clear;
				view.Opaque = false;
			}
			else
			{
				var background = Controller.Theme.HeaderBackgroundColor;
				if (background != null)
				{
					headerLabel.BackgroundColor = background;
				}
			}

			view.BackgroundColor = headerLabel.BackgroundColor;
			
			if (Controller.Theme != null)
			{
				headerLabel.TextAlignment = Controller.Theme.HeaderTextAlignment;

				if (Controller.Theme.HeaderTextColor != null)
					headerLabel.TextColor = Controller.Theme.HeaderTextColor;

				if (Controller.Theme.HeaderTextShadowColor != null)
					headerLabel.ShadowColor = Controller.Theme.HeaderTextShadowColor;

				headerLabel.ShadowOffset = Controller.Theme.HeaderTextShadowOffset;
			}

			view.AddSubview(headerLabel);
			
			return view;
		}
开发者ID:drony,项目名称:MonoMobile.Views,代码行数:56,代码来源:BaseDialogViewSource.cs

示例8: GetHeightForFooter

		public override float GetHeightForFooter(UITableView tableView, int sectionIndex)
		{
			if (Sections.Count > sectionIndex && Sections.ContainsKey(sectionIndex))
			{
				var section = Sections[sectionIndex];
				if (section != null && !string.IsNullOrEmpty(section.FooterText))
				{
					var indentation = UIDevice.CurrentDevice.GetIndentation();
	
					var width = tableView.Bounds.Width - (indentation * 2);
	
					using (var footerLabel = new UILabel())
					{
						footerLabel.Font = UIFont.SystemFontOfSize(15);
						var size = footerLabel.StringSize(section.FooterText, footerLabel.Font);
		
						var height = size.Height * (footerLabel.Font.NumberOfLines(section.FooterText, width));
						
						return height;
					}
				}
			}
			
			//if greater than 0 then the empty footer will display and prevent empty rows from displaying
			return 1;			
		}
开发者ID:drony,项目名称:MonoMobile.Views,代码行数:26,代码来源:BaseDialogViewSource.cs

示例9: GetHeightForHeader

		public override float GetHeightForHeader(UITableView tableView, int sectionIndex)
		{
			if (Sections.Count > sectionIndex && Sections.ContainsKey(sectionIndex))
			{
				var section = Sections[sectionIndex];
				
				if (section != null && !string.IsNullOrEmpty(section.HeaderText))
				{
					var indentation = UIDevice.CurrentDevice.GetIndentation();
					var width = tableView.Bounds.Width - (indentation * 2);
					
					using (var headerLabel = new UILabel())
					{
						headerLabel.Font = UIFont.BoldSystemFontOfSize(UIFont.LabelFontSize);
						var size = headerLabel.StringSize(section.HeaderText, headerLabel.Font);
					
						var height = (float)(size.Height * (headerLabel.Font.NumberOfLines(section.HeaderText, width) + 0.5));
						
						return height;
					}
				}
			}
			return 0;
		}
开发者ID:drony,项目名称:MonoMobile.Views,代码行数:24,代码来源:BaseDialogViewSource.cs

示例10: CreateHeaderView

		private UIView CreateHeaderView(UITableView tableView, string caption)
		{
			var bounds = tableView.Bounds;
			var headerLabel = new UILabel();

			headerLabel.Font = UIFont.BoldSystemFontOfSize(UIFont.LabelFontSize);
			var size = headerLabel.StringSize(caption, headerLabel.Font);
			var rect = new RectangleF(bounds.X + 20, bounds.Y, bounds.Width - 20, size.Height + 10);

			headerLabel.Bounds = rect;
			headerLabel.Frame = headerLabel.Bounds;
			headerLabel.BackgroundColor = UIColor.Clear;
			headerLabel.TextColor = UIColor.FromRGB(76, 86, 108);
			headerLabel.ShadowColor = UIColor.White;
			headerLabel.ShadowOffset = new SizeF(0, 1);
			headerLabel.Text = caption;

			var view = new UIView(rect);
			view.AddSubview(headerLabel);

			return view;
		}
开发者ID:anujb,项目名称:MonoMobile.MVVM,代码行数:22,代码来源:ListViewSource.cs

示例11: Field

			public Field (RectangleF frame, ShareViewController controller, string title)
				: base (frame)
			{
				Controller = controller;

				BackgroundColor = UIColor.White;
				Opaque = true;
				AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

				TitleLabel = new UILabel () {
					BackgroundColor = UIColor.White,
					Font = TextEditorFont,
					Text = title + ":",
					TextColor = UIColor.Gray,
				};

				var w = TitleLabel.StringSize (TitleLabel.Text, TextEditorFont).Width + 8;
				TitleLabel.Frame = new RectangleF (8, 0, w, frame.Height - 1);

				AddSubview (TitleLabel);
			}
开发者ID:sami1971,项目名称:Xamarin.Social,代码行数:21,代码来源:ShareViewController.cs

示例12: SizeThatFitsWidth

		private static SizeF SizeThatFitsWidth(UILabel label, float width)
		{
			var font = label.Font;
			return label.StringSize (
				label.Text, font, new SizeF(width, font.LineHeight * label.Lines),
				label.LineBreakMode);
		}
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:7,代码来源:KeyboardInputView.cs

示例13: LayoutSubviews

        public override void LayoutSubviews()
        {
            base.LayoutSubviews ();
            RectangleF contentRect = this.ContentView.Bounds;

            var label = new UILabel (new RectangleF (0, 0, 0, 0));
            var titleSize = label.StringSize(titleValue,UIFont.SystemFontOfSize (15.0f));

            if (!this.Editing) {
                float boundsX = contentRect.X;
                RectangleF frame;

                frame = new RectangleF ((boundsX + this.level +1) * LEVEL_INDENT+15,0,titleSize.Width,CELL_HEIGHT);
                this.titleLabel.Frame = frame;

                RectangleF imgFrame;
                imgFrame = new RectangleF (((boundsX+this.level+1)*LEVEL_INDENT)-(IMG_HEIGHT_WIDTH-XOFFSET)+5,YOFFSET,IMG_HEIGHT_WIDTH,IMG_HEIGHT_WIDTH);
                this.imageView.Frame = imgFrame;

                var newWidth = ((boundsX + this.level + 1) * LEVEL_INDENT) - (IMG_HEIGHT_WIDTH - XOFFSET) + 40 + (boundsX + this.level + 1) * LEVEL_INDENT + 10 + titleSize.Width;
                if(newWidth > TreeViewViewController.TABLEVIEW_WIDTH ){
                    TreeViewViewController.TABLEVIEW_WIDTH = newWidth;
                }
            }
        }
开发者ID:WenF,项目名称:TreeView,代码行数:25,代码来源:TreeViewViewController.cs

示例14: CreateFooterView

		private UIView CreateFooterView(UITableView tableView, string caption)
		{
			var indentation = UIDevice.CurrentDevice.GetIndentation();
			
			var bounds = tableView.Bounds;
			var footerLabel = new UILabel();
			var width = bounds.Width - (indentation * 2);
			var linefeeds = caption.Count(ch => ch == '\n');
			
			footerLabel.Font = UIFont.SystemFontOfSize(15);
			var size = footerLabel.StringSize(caption, footerLabel.Font);
			
			footerLabel.Lines = 1 + ((int)(size.Width / width)) + linefeeds;
			if (size.Width % width == 0)
				footerLabel.Lines--;
			
			var height = size.Height * (footerLabel.Lines);
			
			var rect = new RectangleF(bounds.X + indentation, bounds.Y, width, height + 10);
			
			footerLabel.Bounds = rect;
			footerLabel.BackgroundColor = UIColor.Clear;
			footerLabel.TextAlignment = UITextAlignment.Center;
			footerLabel.LineBreakMode = UILineBreakMode.WordWrap;
			footerLabel.TextColor = UIColor.FromRGB(76, 86, 108);
			footerLabel.ShadowColor = UIColor.White;
			footerLabel.ShadowOffset = new SizeF(0, 1);
			footerLabel.Text = caption;
			
			return footerLabel;
		}
开发者ID:eiu165,项目名称:MonoMobile.Views,代码行数:31,代码来源:DialogViewDataSource.cs

示例15: GetHeightForFooter

		public override float GetHeightForFooter(UITableView tableView, int sectionIndex)
		{
			var section = GetSection(sectionIndex);

			if (section != null && !string.IsNullOrEmpty(section.FooterText))
			{
				var indentation = UIDevice.CurrentDevice.GetIndentation();

				var width = tableView.Bounds.Width - (indentation * 2);

				var footerLabel = new UILabel();
			
				footerLabel.Font = UIFont.SystemFontOfSize(15);
				var size = footerLabel.StringSize(section.FooterText, footerLabel.Font);

				var height = size.Height * (footerLabel.Font.NumberOfLines(section.FooterText, width));

				return height;
			}
			
			return 0;			
		}
开发者ID:vknair74,项目名称:MonoMobile.Views,代码行数:22,代码来源:DialogViewDataSource.cs


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