「Swift」TextビューにfontWeight()でフォントの太さを指定する

書式
.fontWeight(.フォントの太さ)
fontWeightで表示するフォントの太さを指定します。
フォントの太さの項目
ultraLight、thin、light、regular、medium、semibold

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
struct ContentView: View {
var body: some View {
VStack {
Text("超軽量").fontWeight(.ultraLight)
Text("細い").fontWeight(.thin)
Text("ライト").fontWeight(.light)
Text("通常").font(.body).fontWeight(.regular)
Text("中").fontWeight(.medium)
Text("セミボールド").fontWeight(.semibold)
Text("太字").fontWeight(.bold)
Text("BB").fontWeight(.heavy)
Text("CC").fontWeight(.black)
}
}
}
struct ContentView: View { var body: some View { VStack { Text("超軽量").fontWeight(.ultraLight) Text("細い").fontWeight(.thin) Text("ライト").fontWeight(.light) Text("通常").font(.body).fontWeight(.regular) Text("中").fontWeight(.medium) Text("セミボールド").fontWeight(.semibold) Text("太字").fontWeight(.bold) Text("BB").fontWeight(.heavy) Text("CC").fontWeight(.black) } } }
struct ContentView: View {
    var body: some View {
        VStack {
            Text("超軽量").fontWeight(.ultraLight)
            Text("細い").fontWeight(.thin)
            Text("ライト").fontWeight(.light)
            Text("通常").font(.body).fontWeight(.regular)
            Text("中").fontWeight(.medium)
            Text("セミボールド").fontWeight(.semibold)
            Text("太字").fontWeight(.bold)
            Text("BB").fontWeight(.heavy)
            Text("CC").fontWeight(.black)
        }
    }
}

 

Swift

Posted by arkgame