• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Spritekit

My WordPress site

  • Top
  • SpriteKitBase
    • Collision
    • Enumerated
    • Shooting
    • Breakout
    • Physics1
      • physics4
      • physics3
      • Physics2
  • SwiftUI&SpriteKit
    • TabScroll
    • LocalWebView
      • Counter
      • StateObject
      • Button
      • SceneMove
    • Swift Learning
  • Photo Gallery
    • Photo Galler 2
    • Photo Gallery 3
    • リンク
      • プロフィール
      • p5.play test

Text

09/04/2022 by kyougif


import SwiftUI


extension Text {
 func textModifier(color: Color) -> some View {
    self
    .font(.system(size: 14, design: .monospaced))
    .fontWeight(.bold) // Viewに準拠していないModifier
     .multilineTextAlignment(.center) // Viewに準拠していないModifier
     .padding(7)
    .overlay(RoundedRectangle(cornerRadius: 10).stroke(lineWidth: 1))
    .foregroundColor(color)
  }
}

struct ContentView: View {
    let pi = 3.141519   // 円周率z
@State private var text: String = """
       A text editor view allows you to display and edit multiline,scrollable text in your app’s user interface.
       複数行のスクロール可能なテキストを表示・編集できる
       """

var body: some View {
   VStack {
 Text("myテキスト")
    .textModifier(color: .red)
Text("円周率:\(pi, specifier: "%.2f")")
   .font(.system(size: 40, weight: .black, design: .default))
   .foregroundColor(.green)
   .padding(.top, 10)

TextEditor(text: $text)
 .frame(width: 320, height: 150)
 .padding(.bottom, -20)

 Text("Hello, world!").kerning(5)
 .font(.custom("Times-Roman", size: 35))
 .padding(.top, 20)
  Text("エリア 200 x 200 の中に文章を中央寄りで表示します。よろしくお願いいたします。")
   .frame(width: 280, height: 100, alignment: .leading)
   .multilineTextAlignment(.leading)
   .lineSpacing(10)
 Text("SwiftUI")
 .font(.system(size: 50, weight: .black, design: .default))
 Divider().padding(.bottom, 10)
    Text("SwiftUIで") +
    Text("一部の文字").foregroundColor(.red).fontWeight(.bold) + Text("だけを装飾する。")
 }
 }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Filed Under: Programming, swiftui

Primary Sidebar

最近の投稿

  • ObservableObj
  • SideMenu
  • TabScroll
  • Text
  • TappedNodes
  • Collision2
  • CoreMotion
  • Collision
  • Timer
  • Enumerated
  • Random
  • SwiftUI-List
  • Shooting
  • Sound
  • Camera
  • SpriteSheet
  • SKPhysics42
  • physics4
  • physics3
  • Physics2

アーカイブ

  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2014年9月
  • 2014年5月

カテゴリー

  • Programming
  • spritekit
  • swiftui

固定ページ

  • Home
  • p5.play test
  • Photo Galler 2
  • Photo Gallery
  • Photo Gallery 3
  • Top
  • プロフィール
  • リンク

Copyright © 2026 · Genesis-child on Genesis Framework · WordPress · Log in