Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active May 8, 2020 22:25
Show Gist options
  • Save Koze/376b0ff231107569f073f026eac2e688 to your computer and use it in GitHub Desktop.
Save Koze/376b0ff231107569f073f026eac2e688 to your computer and use it in GitHub Desktop.
Japanese font without Japanese character causes the clip at the bottom. The final workaround.
import SwiftUI
struct SmapleView: View {
let ctFont = CTFontCreateWithName("HiraginoSans-W3" as CFString, 50, nil)
var ctFontDescender: CGFloat {
CTFontGetDescent(ctFont)
}
let borderColor = Color(.systemBlue)
var body: some View {
VStack(spacing: 20) {
HStack(spacing: 10) {
Text("Copy")
.font(.init(ctFont))
.border(borderColor)
Text("Copy")
.font(.init(ctFont))
.baselineOffset(ctFontDescender)
.offset(y: descent / 2)
// .padding(.top, ctFontDescender)
.border(borderColor)
}
HStack(spacing: 10) {
Text("コピー")
.font(.init(ctFont))
.border(borderColor)
Text("コピー")
.font(.init(ctFont))
.baselineOffset(ctFontDescender)
.offset(y: descent / 2)
// .padding(.top, ctFontDescender)
.border(borderColor)
}
}
}
}
struct SmapleView_Previews: PreviewProvider {
static var previews: some View {
SmapleView()
}
}
@Koze
Copy link
Author

Koze commented May 8, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment