admin管理员组文章数量:1026319
I recently investigated hyphenation issues in an app I am working on, and built the following simple example:
HStack {
Text("Gewerberechtsschutzversicherung")
.font(.body)
.background(.red)
Text("Gewerberechtsschutzversicherung")
.font(.system(size: 17))
.background(.blue)
}
The result was this:
Turns out that setting any sort of custom font size instead of using Apple's predefined enum (.body
, .callout
etc.) will disable automatic hyphenation of words in SwiftUI.
Is there any way to enable automatic hyphenation in such a scenario? Since the app uses a Styleguide where it retrieves fonts from, using the Apple predefined sizes is not an option here and this disables hyphenation for the entire App. Soft hyphens still work but of course have to be added to every string manually then.
I recently investigated hyphenation issues in an app I am working on, and built the following simple example:
HStack {
Text("Gewerberechtsschutzversicherung")
.font(.body)
.background(.red)
Text("Gewerberechtsschutzversicherung")
.font(.system(size: 17))
.background(.blue)
}
The result was this:
Turns out that setting any sort of custom font size instead of using Apple's predefined enum (.body
, .callout
etc.) will disable automatic hyphenation of words in SwiftUI.
Is there any way to enable automatic hyphenation in such a scenario? Since the app uses a Styleguide where it retrieves fonts from, using the Apple predefined sizes is not an option here and this disables hyphenation for the entire App. Soft hyphens still work but of course have to be added to every string manually then.
Share Improve this question edited Nov 18, 2024 at 18:33 Rob 15.2k30 gold badges48 silver badges73 bronze badges asked Nov 18, 2024 at 10:13 BlackWolfBlackWolf 5,6395 gold badges37 silver badges65 bronze badges1 Answer
Reset to default 1It turns out that adding a soft hyphen anywhere in the string also re-enables automatic hyphenation. So this will use automatic hyphenation on both strings:
HStack {
Text("Gewerberechtsschutzversicherung")
.font(.body)
.background(.red)
Text("\u{00AD}Gewerberechtsschutzversicherung")
.font(.system(size: 17))
.background(.blue)
}
I recently investigated hyphenation issues in an app I am working on, and built the following simple example:
HStack {
Text("Gewerberechtsschutzversicherung")
.font(.body)
.background(.red)
Text("Gewerberechtsschutzversicherung")
.font(.system(size: 17))
.background(.blue)
}
The result was this:
Turns out that setting any sort of custom font size instead of using Apple's predefined enum (.body
, .callout
etc.) will disable automatic hyphenation of words in SwiftUI.
Is there any way to enable automatic hyphenation in such a scenario? Since the app uses a Styleguide where it retrieves fonts from, using the Apple predefined sizes is not an option here and this disables hyphenation for the entire App. Soft hyphens still work but of course have to be added to every string manually then.
I recently investigated hyphenation issues in an app I am working on, and built the following simple example:
HStack {
Text("Gewerberechtsschutzversicherung")
.font(.body)
.background(.red)
Text("Gewerberechtsschutzversicherung")
.font(.system(size: 17))
.background(.blue)
}
The result was this:
Turns out that setting any sort of custom font size instead of using Apple's predefined enum (.body
, .callout
etc.) will disable automatic hyphenation of words in SwiftUI.
Is there any way to enable automatic hyphenation in such a scenario? Since the app uses a Styleguide where it retrieves fonts from, using the Apple predefined sizes is not an option here and this disables hyphenation for the entire App. Soft hyphens still work but of course have to be added to every string manually then.
Share Improve this question edited Nov 18, 2024 at 18:33 Rob 15.2k30 gold badges48 silver badges73 bronze badges asked Nov 18, 2024 at 10:13 BlackWolfBlackWolf 5,6395 gold badges37 silver badges65 bronze badges1 Answer
Reset to default 1It turns out that adding a soft hyphen anywhere in the string also re-enables automatic hyphenation. So this will use automatic hyphenation on both strings:
HStack {
Text("Gewerberechtsschutzversicherung")
.font(.body)
.background(.red)
Text("\u{00AD}Gewerberechtsschutzversicherung")
.font(.system(size: 17))
.background(.blue)
}
本文标签: swiftuiEnabling automatic hyphenation with custom font sizeStack Overflow
版权声明:本文标题:swiftui - Enabling automatic hyphenation with custom font size - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745627077a2159928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论