【发布时间】:2020-08-25 13:07:26
【问题描述】:
目前,我一直在使用.lineSpacing(...),但这仅适用于多行文本。
/// Sets the amount of space between lines of text in this view.
///
/// - Parameter lineSpacing: The amount of space between the bottom of one
/// line and the top of the next line.
@inlinable public func lineSpacing(_ lineSpacing: CGFloat) -> some View
这意味着我更难从草图/figma 中准确翻译字体,我需要使用填充以使其正确。下面是一个例子:
VStack {
// Line spacing is ignored.
Text("Hello, World!")
.background(Color.green)
.lineSpacing(50)
Spacer()
// Line spacing is correct.
Text("Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.")
.background(Color.green)
.lineSpacing(50)
}
【问题讨论】:
-
我没有明白你的意思,但是,如果它适合你,试试这个:在一行的末尾添加“\n”
Text -
您对第一个文本有何期望?字体如何与主题相关 - 两个文本块中的字体相同?
-
@EnesKaraosman 我不想添加新行,我想增加单行的空间。
-
我无法说服自己,单行应该如何有间距。
lineSpacing方法名很清楚,你也访问过 SwiftUI 的界面看解释,也有说“设置行之间的空间量...”:( -
SwiftUI 文本不提供 lineHeight 属性(行间距是另一种野兽)。您可以尝试对齐“firstTextBaseLine”以获得所需的行为。或者,使用带有属性字符串的“UILabel”(通过“UIViewRepresentable”)(在段落样式中指定行高)。
标签: ios swift iphone xcode swiftui