gpt4 book ai didi

SwiftUI 链接长文本对齐多行

转载 作者:行者123 更新时间:2023-12-03 08:02:13 25 4
gpt4 key购买 nike

问题

我正在使用 SwiftUI 的 Link从应用程序打开 Safari。但我有一个很长的链接文本。

目前,文本的第二行始终保持居中对齐。

我想要什么

我希望能够使用leading TextAlignment有了它。

所以我尝试使用 multilineTextAlignment但没有成功。

代码

Link("Some long text even very looong even that long text here!", destination: URL(string: "https://www.apple.com/")!)
.multilineTextAlignment(.leading)

需要帮助。

最佳答案

解决方案

我的解决方案是使用链接本身的另一个签名和multilineTextAlignment

Link(destination: URL(string: "https://www.apple.com/")!) {
Text("Some long text even very looong even that long text here!")
.multilineTextAlignment(.leading)
}

来自苹果文档

public struct Link<Label> : View where Label : View {

/// Creates a control, consisting of a URL and a label, used to navigate
/// to the given URL.
///
/// - Parameters:
/// - destination: The URL for the link.
/// - label: A view that describes the destination of URL.
public init(destination: URL, @ViewBuilder label: () -> Label)

希望能帮助别人!

最佳

关于SwiftUI 链接长文本对齐多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73699299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com