From eda3fb873e59544ff36301b51e05aef64f87b0f9 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期五, 27 八月 2021 13:21:21 +0800
Subject: [PATCH] Merge branch 'newBranch1' of http://172.16.1.23:6688/r/~wxr/HDL_APP_Project into newBranch1
---
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