From e1a8f2f7e4d850beedeb1469610b878c1427e976 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期三, 15 十二月 2021 09:01:53 +0800
Subject: [PATCH] 更新

---
 HDL_ON/UI/UI0-Public/Widget/TextButton.cs |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 114 insertions(+), 0 deletions(-)

diff --git a/HDL_ON/UI/UI0-Public/Widget/TextButton.cs b/HDL_ON/UI/UI0-Public/Widget/TextButton.cs
index c0a5b02..cebc715 100644
--- a/HDL_ON/UI/UI0-Public/Widget/TextButton.cs
+++ b/HDL_ON/UI/UI0-Public/Widget/TextButton.cs
@@ -1,7 +1,11 @@
 锘縰sing System;
 using Shared;
+
 #if __IOS__
 using UIKit;
+using Foundation;
+#else
+using Android.Graphics;
 #endif
 
 namespace HDL_ON.UI
@@ -9,6 +13,7 @@
     /// <summary>
     /// TextButton
     /// 瑙e喅iOS 鏂囨湰鍒拌竟妗嗘湁杈硅窛闂
+    /// 鏀寔鏍规嵁鏂囨湰鍔ㄦ�佽绠楅珮搴�
     /// </summary>
     public class TextButton : Button
     {
@@ -20,5 +25,114 @@
 #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;
+        /// <summary>
+        /// 璁剧疆琛岄棿璺�
+        /// </summary>
+        public int LineSpacing
+        {
+            set
+            {
+                _lineSpacing = value;
+                SetButtonLineSpacing(_lineSpacing);
+            }
+        }
+
+
+#if __IOS__
+        /// <summary>
+        /// 鎸夐挳璁剧疆琛岃窛鏂规硶
+        /// </summary>
+        /// <param name="spacing"></param>
+        void SetButtonLineSpacing(int spacing)
+        {
+            UIStringAttributes stringAttributes = new UIStringAttributes
+            {
+                Font = (this.uiView as MyButton).TitleLabel.Font,
+                ForegroundColor = UIColor.Black,
+                ParagraphStyle = new NSMutableParagraphStyle() { LineSpacing = spacing }
+            };
+            var AttributedText = new NSMutableAttributedString(Text);
+            AttributedText.AddAttributes(stringAttributes, new NSRange(0, Text.Length));
+            (this.uiView as MyButton).TitleLabel.AttributedText = AttributedText;
+        }
+
+        /// <summary>
+        /// 鏄剧ず褰撳墠鏂囧瓧闇�瑕佸嚑琛�
+        /// </summary>
+        /// <returns></returns>
+        public int GetNeedLinesWithWidth()
+        {
+            return (this.GetTextWidth() / this.Width) * this.Height;
+            //return 0;
+        }
+
+
+#else
+
+        /// <summary>
+        /// 鎸夐挳璁剧疆琛岃窛鏂规硶
+        /// </summary>
+        /// <param name="spacing"></param>
+        void SetButtonLineSpacing(int spacing)
+        {
+           (this.AndroidView as Android.Widget.Button).SetLineSpacing(spacing, 1);
+        }
+
+        /// <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