gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 13/32: width of rendered string


From: gnunet
Subject: [taler-taler-ios] 13/32: width of rendered string
Date: Mon, 16 Oct 2023 00:03:11 +0200

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit 8b08e6e2c4df24682ed10ffb8ddb98f7bf523697
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Oct 13 10:31:38 2023 +0200

    width of rendered string
---
 TalerWallet1/Helper/TalerStrings.swift | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/TalerWallet1/Helper/TalerStrings.swift 
b/TalerWallet1/Helper/TalerStrings.swift
index d1443b4..6c39f67 100644
--- a/TalerWallet1/Helper/TalerStrings.swift
+++ b/TalerWallet1/Helper/TalerStrings.swift
@@ -3,9 +3,9 @@
  * See LICENSE.md
  */
 import Foundation
+import UIKit
 
 extension StringProtocol {
-
     func trimURL() -> String {
         if let url = URL(string: String(self)) {
             if let host = url.host {
@@ -15,3 +15,14 @@ extension StringProtocol {
         return String(self)
     }
 }
+
+extension String {
+    func widthOfString(usingUIFont font: UIFont) -> CGFloat {
+        let fontAttributes = [NSAttributedString.Key.font: font]
+        let size = self.size(withAttributes: fontAttributes)
+        return size.width
+    }
+}
+// This would be used like so:
+// let uiFont = UIFont.systemFont(ofSize: 17, weight: .bold)
+// let width = "SomeString".widthOfString(usingUIFont: uiFont)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]