
- 1行目: 明示的にboldを指定した
- 2行目: 暗黙的にboldを指定した(
boldSystemFont(ofSize:)
*1, bold()
*2 )
- 3行目: 明示的にsemiboldを指定した
環境
- macOS: Sonoma 14.6.1 (23G93)
- Xcode: 15.4(15F31d)
- Swfit: 5.10
コード
import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
VStack(alignment: .leading, spacing: 4) {
Text("UIKit")
VStack(alignment: .leading, spacing: 0) {
Label(font: .systemFont(ofSize: 20, weight: .bold))
.fixedSize()
Label(font: .boldSystemFont(ofSize: 20))
.fixedSize()
Label(font: .systemFont(ofSize: 20, weight: .semibold))
.fixedSize()
}
}
VStack(alignment: .leading, spacing: 4) {
Text("SwiftUI")
VStack(alignment: .leading, spacing: 0) {
Text("Lorem ipsum")
.font(.system(size: 20, weight: .bold))
Text("Lorem ipsum")
.font(.system(size: 20))
.bold()
Text("Lorem ipsum")
.font(.system(size: 20, weight: .semibold))
}
}
}
}
}
struct Label: UIViewRepresentable {
let font: UIFont
func makeUIView(context: Context) -> UILabel {
let label = UILabel()
label.text = "Lorem ipsum"
label.font = font
return label
}
func updateUIView(_ uiView: UILabel, context: Context) {}
}