Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active May 8, 2020 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

use offset
Screenshot 2020-05-09 7 05 21

use padding
Screenshot 2020-05-09 2 26 37

@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