当前位置: 移动技术网 > 移动技术>移动开发>IOS > Xamarin.iOS UILable行间距设置

Xamarin.iOS UILable行间距设置

2018年01月22日  | 移动技术网移动技术  | 我要评论

Xamarin.iOS UILable行间距设置:从上个月项目中就出现了文字要设置行间距的问题。在网上搜索了好久,搜索结果全是iOS原生开发的。

做Xamarin开发的应该都知道,Xamarin的API和原生都是一一对应的。

于是慢慢试着照着OC代码转成c#的。转换结果如下:

NSMutableAttributedString attributedString = new NSMutableAttributedString (cellData.BriefDescription);
var att = new UIStringAttributes ();
att.ParagraphStyle = new NSParagraphStyle ();
att.ParagraphStyle.LineSpacing = 12.0f;
att.ParagraphStyle.MaximumLineHeight = 24.0f;
att.ParagraphStyle.MinimumLineHeight = 24.0f;
attributedString.AddAttributes(att.Dictionary, new NSRange (0,cellData.BriefDescription.Length ));
lable.AttributedText = attributedString;`
但是却出不来效果。

为了不耽误项目的进度,就把这个问题放下往下做。一直到了这个月的今天。下面说下Xamarin.iOS中给UILable设置行间距的方法:

// 行间距
					UIStringAttributes strAttri = new UIStringAttributes
					{
						Font = UIFont.SystemFontOfSize(15f),
						ForegroundColor = MvxTouchColor.GrayTwelve,
						ParagraphStyle = new NSMutableParagraphStyle() { LineSpacing = 5.0f}
					};
					var attrText = new NSMutableAttributedString(_showText);
					attrText.AddAttributes(strAttri, new NSRange(0, _showText.Length));
					lable.AttributedText = attrText;

大家注意,最后一句是给UIlable设置文字的,和以前的Text不一样。

还有一点需要注意,我一开始用的不是UIlable,是UIButton(应该都知道UIButton包含了UIlable和UIimage)

但是出不来。

至于为啥等我研究好了再回来补充。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网