文章出處
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)
但是出不來。
至于為啥等我研究好了再回來補充。
看文倉www.kanwencang.com網友整理上傳,為您提供最全的知識大全,期待您的分享,轉載請注明出處。
歡迎轉載:http://www.kanwencang.com/bangong/20170120/92442.html
文章列表
全站熱搜