From 5ea6aa8ea047d4d7b6137fa86c03109aeb1b67ff Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期五, 18 十二月 2020 18:03:18 +0800 Subject: [PATCH] Merge branch 'CJL' into NewFilePath --- HDL_ON/UI/UI0-Public/Widget/TextButton.cs | 91 ++++++++++++++++++++++++++++----------------- 1 files changed, 57 insertions(+), 34 deletions(-) diff --git a/HDL_ON/UI/UI0-Public/Widget/TextButton.cs b/HDL_ON/UI/UI0-Public/Widget/TextButton.cs index 4148731..cebc715 100755 --- a/HDL_ON/UI/UI0-Public/Widget/TextButton.cs +++ b/HDL_ON/UI/UI0-Public/Widget/TextButton.cs @@ -4,6 +4,8 @@ #if __IOS__ using UIKit; using Foundation; +#else +using Android.Graphics; #endif namespace HDL_ON.UI @@ -11,7 +13,7 @@ /// <summary> /// TextButton /// 瑙e喅iOS 鏂囨湰鍒拌竟妗嗘湁杈硅窛闂 - /// + /// 鏀寔鏍规嵁鏂囨湰鍔ㄦ�佽绠楅珮搴� /// </summary> public class TextButton : Button { @@ -22,6 +24,45 @@ (this.uiView as MyButton).ContentEdgeInsets = new UIEdgeInsets(0, 0, 0, 0); #endif + } + + /// <summary> + /// 璁剧疆闇�瑕侀檺鍒剁殑鏈�澶ц鏁� + /// 浣嗘槸瓒呰繃琛屾暟鐨勮瘽浼氱己灏戠渷鐣ュ彿...锛屾殏鏃舵棤娉曡В鍐� + /// </summary> + public int MaxLine = 0; + /// <summary> + /// 鍔ㄦ�佽绠楅珮搴� + /// 璧嬪�兼枃鏈悗鍜屾寚瀹氬搴﹀悗锛岄�氳繃璁$畻鐪熷疄鐨勯渶瑕佸搴﹀拰鎸囧畾瀹藉害绠楀嚭澶氳闇�瑕佺殑鐪熷疄楂樺害 + /// 璇ユ柟娉曟湁璇樊涓嶈兘100%鍑嗙‘ + /// 鏈�姝g‘鏂规硶鏄牴鎹� 鍗曡鍗曚釜瀛椾綋鐨勯珮搴﹀姞涓婅璺濇潵璁$畻 + /// </summary> + /// <returns></returns> + public int GetMoreLineNeedHeight() + { + //璁$畻闇�瑕佺殑鐪熷疄瀹藉害 + int needWidth = this.GetTextWidth(); + //璁$畻鍦ㄦ寚瀹氬搴︽儏鍐典笅锛岄渶瑕佺殑鐪熷疄琛屾暟 + int line = (needWidth / this.Width); + //姹備綑 + int modValue = (needWidth % this.Width); + //浣欏ぇ浜�0锛屽垯澶氬姞涓�琛� + if (modValue > 0) + { + line = line + 1; + } + if (line > 0) + { + if(MaxLine != 0) + { + line = Math.Min(line, MaxLine); + } + return line * this.Height; + } + else + { + return this.Height; + } } int _lineSpacing; @@ -60,42 +101,13 @@ /// 鏄剧ず褰撳墠鏂囧瓧闇�瑕佸嚑琛� /// </summary> /// <returns></returns> - int GetNeedLinesWithWidth() + public int GetNeedLinesWithWidth() { - return 0; + return (this.GetTextWidth() / this.Width) * this.Height; + //return 0; } - /** - -// @param width 缁欏畾涓�涓搴� -// @return 杩斿洖琛屾暟 -// */ -//- (NSInteger) needLinesWithWidth:(CGFloat) width -// { -// //鍒涘缓涓�涓猯abe -// UILabel * label = [[UILabel alloc] -// init]; -// //font鍜屽綋鍓峫abel淇濇寔涓�鑷� -// label.font = self.font; -// NSString* text = self.text; -// NSInteger sum = 0; -// //鎬昏鏁板彈鎹㈣绗﹀奖鍝嶏紝鎵�浠ヨ繖閲岃绠楁�昏鏁帮紝闇�瑕佺敤鎹㈣绗﹀垎闅旇繖娈垫枃瀛楋紝鐒跺悗璁$畻姣忔鏂囧瓧鐨勮鏁帮紝鐩稿姞鍗虫槸鎬昏鏁般�� -// NSArray* splitText = [text componentsSeparatedByString: @"\n"]; -// for (NSString* sText in splitText) -// { -// label.text = sText; -// //鑾峰彇杩欐鏂囧瓧涓�琛岄渶瑕佺殑size -// CGSize textSize = [label systemLayoutSizeFittingSize: CGSizeZero]; -// //size.width/鎵�闇�瑕佺殑width 鍚戜笂鍙栨暣灏辨槸杩欐鏂囧瓧鍗犵殑琛屾暟 -// NSInteger lines = ceilf(textSize.width / width); -// //褰撴槸0鐨勬椂鍊欙紝璇存槑杩欐槸鎹㈣锛岄渶瑕佹寜涓�琛岀畻銆� -// lines = lines == 0 ? 1 : lines; -// sum += lines; -// } -// return sum; -// } - //#elif __Android__ #else /// <summary> @@ -107,8 +119,19 @@ (this.AndroidView as Android.Widget.Button).SetLineSpacing(spacing, 1); } -#endif + /// <summary> + /// + /// </summary> + /// <returns></returns> + int GetTextHeight() + { + string text = "Text"; + Rect rect = new Rect(); + (this.AndroidView as Android.Widget.Button).Paint.GetTextBounds(text, 0, text.Length, rect); + return rect.Height(); } +#endif + } -- Gitblit v1.8.0