見出し画像

【じっくりSw1ftUI61】実践編31〜第43章 カスタマイズされた SwiftUI ProgressView の作成

さてと、前回

で、

ジェスチャの基本

はやったので〜〜〜今回は、

プログレスバーの基本

についてやってく🕺

オイラの学びなんざ不要な人は

にサンプルコードなんかも載ってるみたいだからそっちでやればいいんじゃね👀💦
んだば、今回も早速


じっくり第43章を読んでく👓

概要なんかでは、

プログレスバーに色んなタイプがあることを羅列してるだけなんで、、、

早速動かす

import SwiftUI

struct Essentials43ContentsView: View {
    var body: some View {
        Text("")
    }
}

#Preview {
    Essentials43ContentsView()
}

で今回もまっさらな新規のSwiftUIファイルを用意

真っ白〜〜〜〜

まずは基本から

import SwiftUI

struct Essentials43ContentsView: View {
    var body: some View {
        E43ProgressBarStandardView()
    }
}

struct E43ProgressBarStandardView: View {
    @State private var progressValue: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(LinearProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
    }
}

#Preview {
    Essentials43ContentsView()
}
初期値〜〜〜
てな感じ〜〜〜

円状プログレスバー

import SwiftUI

struct Essentials43ContentsView: View {
    var body: some View {
        ScrollView{
            E43ProgressBarStandardView()
            E43ProgressBarCircularView()
        }
    }
}

struct E43ProgressBarStandardView: View {
    @State private var progressValue: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(LinearProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
    }
}

struct E43ProgressBarCircularView: View {
    @State private var progressValue: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(CircularProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
    }
}

#Preview {
    Essentials43ContentsView()
}
初期値
てな感じ

まとめて〜〜〜

struct E43ProgressBarCircularView: View {
    @State private var progressValue: Double = 0.0
    @State private var progressValue1: Double = 0.0
    @State private var progressValue2: Double = 0.0
    @State private var progressValue3: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(CircularProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
        VStack{
            ProgressView("進捗1:\(Int(progressValue1))",value: progressValue1, total: 100)
                .padding()
            Slider(value: $progressValue1,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗2:\(Int(progressValue2))",value: progressValue2, total: 10000)
                .padding()
            Slider(value: $progressValue2,in: 0...10000,step:200)
                .padding()
            ProgressView("進捗3:\(Int(progressValue3))",value: progressValue3, total: 1000000)
                .padding()
            Slider(value: $progressValue3,in: 0...1000000,step:20000)
                .padding()
        }
        .progressViewStyle(CircularProgressViewStyle())
        .padding()
    }
}
てな感じ

不確定なインジケーター

struct E43InterminateProgressView:View {
    var body: some View {
        ProgressView("進捗")
    }
}
一番下。ま、これだけでも成立はするみたいね藁😝

カスタマイズ

まずはプログレスビュースタイルの独自構造体を

//【雛型】
struct E43CustomProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
        //自分で設定
    }
}

てな感じで用意して〜〜〜

struct E43CustomProgressView: View {
    @State private var progressValue: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(E43ShadowProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 1)
                .padding()
        }
    }
}

struct E43ShadowProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
            .tint(Color.red)
            .shadow(
                color: Color(red:0,green: 0.8,blue:0.1),
                radius: 6.0,
                x: 2.0,
                y: 2.0
            )
            .progressViewStyle(LinearProgressViewStyle())
    }
}

てな感じにしてあげると、

てな感じ👀💦だいぶ、楽しい🤤

他にも〜〜〜

struct E43PercentProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        let percent = Int(configuration.fractionCompleted!*100)
        return Text("進捗:\(percent)%完了")
    }
}

てな感じで追加して

struct E43CustomProgressView: View {
    @State private var progressValueShadow: Double = 0.0
    @State private var progressValuePercent: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValueShadow))",value: progressValueShadow, total: 100)
                .progressViewStyle(E43ShadowProgressViewStyle())
                .padding()
            Slider(value: $progressValueShadow,in: 0...100,step: 1)
                .padding()
            
            ProgressView("進捗:\(Int(progressValuePercent))",value: progressValuePercent, total: 100)
                .progressViewStyle(E43PercentProgressViewStyle())
                .padding()
            Slider(value: $progressValuePercent,in: 0...100,step: 1)
                .padding()
        }
    }
}

てな感じにすると、

てな感じ

最後にかっちょ良く

struct E43CircularPercentProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        let degrees = configuration.fractionCompleted!*360
        let percent = Int(configuration.fractionCompleted!*100)
        return VStack{
            E43CircleGraph(
                startAngle: .degrees(0),
                endAngle: .degrees(degrees)
            )
            .frame(width: 300,height: 300)
            .padding()
            Text("進捗:\(percent)%完了")
        }
    }
}

struct E43CircleGraph: Shape {
    var startAngle: Angle
    var endAngle: Angle
    
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.addArc(
            center: CGPoint(x:rect.midX, y: rect.midY),
            radius: rect.width / 2,
            startAngle: startAngle,
            endAngle: endAngle,
            clockwise: true
        )
        return path.strokedPath(.init(lineWidth: 100,dash: [6,4]))
    }
}

てな感じで

struct E43CustomProgressView: View {
    @State private var progressValueShadow: Double = 0.0
    @State private var progressValuePercent: Double = 0.0
    @State private var progressValueCircle: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValueShadow))",value: progressValueShadow, total: 100)
                .progressViewStyle(E43ShadowProgressViewStyle())
                .padding()
            Slider(value: $progressValueShadow,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗:\(Int(progressValuePercent))",value: progressValuePercent, total: 100)
                .progressViewStyle(E43PercentProgressViewStyle())
                .padding()
            Slider(value: $progressValuePercent,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗:\(Int(progressValueCircle))",value: progressValueCircle, total: 100)
                .progressViewStyle(E43CircularPercentProgressViewStyle())
                .padding()
            Slider(value: $progressValueCircle,in: 0...100,step: 1)
                .padding()
        }
    }
}

てな感じにして〜〜〜

ホイ、完了

以上🕺

今回のコードまとめ

import SwiftUI

struct Essentials43ContentsView: View {
    var body: some View {
        ScrollView{
            E43ProgressBarStandardView()
            E43ProgressBarCircularView()
            E43InterminateProgressView()
            E43CustomProgressView()
        }
        .safeAreaPadding()
    }
}

struct E43ProgressBarStandardView: View {
    @State private var progressValue: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(LinearProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
    }
}

struct E43ProgressBarCircularView: View {
    @State private var progressValue: Double = 0.0
    @State private var progressValue1: Double = 0.0
    @State private var progressValue2: Double = 0.0
    @State private var progressValue3: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(CircularProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
        VStack{
            ProgressView("進捗1:\(Int(progressValue1))",value: progressValue1, total: 100)
                .padding()
            Slider(value: $progressValue1,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗2:\(Int(progressValue2))",value: progressValue2, total: 10000)
                .padding()
            Slider(value: $progressValue2,in: 0...10000,step:200)
                .padding()
            ProgressView("進捗3:\(Int(progressValue3))",value: progressValue3, total: 1000000)
                .padding()
            Slider(value: $progressValue3,in: 0...1000000,step:20000)
                .padding()
        }
        .progressViewStyle(CircularProgressViewStyle())
        .padding()
    }
}

struct E43InterminateProgressView:View {
    var body: some View {
        ProgressView("進捗")
    }
}

//【雛型】
struct E43CustomProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
        //自分で設定
    }
}

struct E43ShadowProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
            .tint(Color.red)
            .shadow(
                color: Color(red:0,green: 0.8,blue:0.1),
                radius: 6.0,
                x: 2.0,
                y: 2.0
            )
            .progressViewStyle(LinearProgressViewStyle())
    }
}

struct E43PercentProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        let percent = Int(configuration.fractionCompleted!*100)
        return Text("進捗:\(percent)%完了")
    }
}

struct E43CircularPercentProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        let degrees = configuration.fractionCompleted!*360
        let percent = Int(configuration.fractionCompleted!*100)
        return VStack{
            E43CircleGraph(
                startAngle: .degrees(0),
                endAngle: .degrees(degrees)
            )
            .frame(width: 300,height: 300)
            .padding()
            Text("進捗:\(percent)%完了")
        }
    }
}

struct E43CircleGraph: Shape {
    var startAngle: Angle
    var endAngle: Angle
    
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.addArc(
            center: CGPoint(x:rect.midX, y: rect.midY),
            radius: rect.width / 2,
            startAngle: startAngle,
            endAngle: endAngle,
            clockwise: true
        )
        return path.strokedPath(.init(lineWidth: 100,dash: [6,4]))
    }
}

struct E43CustomProgressView: View {
    @State private var progressValueShadow: Double = 0.0
    @State private var progressValuePercent: Double = 0.0
    @State private var progressValueCircle: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValueShadow))",value: progressValueShadow, total: 100)
                .progressViewStyle(E43ShadowProgressViewStyle())
                .padding()
            Slider(value: $progressValueShadow,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗:\(Int(progressValuePercent))",value: progressValuePercent, total: 100)
                .progressViewStyle(E43PercentProgressViewStyle())
                .padding()
            Slider(value: $progressValuePercent,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗:\(Int(progressValueCircle))",value: progressValueCircle, total: 100)
                .progressViewStyle(E43CircularPercentProgressViewStyle())
                .padding()
            Slider(value: $progressValueCircle,in: 0...100,step: 1)
                .padding()
        }
    }
}

#Preview {
    Essentials43ContentsView()
}

Apple公式

さてと、次回は

進捗の円グラフなんかも出てきたところで、SwiftUIでチャート図を表示する方法を紹介した

第44章 SwiftUIチャートを使ったプレゼンテーションデータ

に入ってく〜〜〜

記事公開後、

いつもどおり、

でやった操作を〜〜〜

てな
てな
てなで
ホイ、完了

サンプルコード

◾️Essentials43.swift

import SwiftUI
import WebKit

//タイトル
let essentialsChapter43NavigationTitle = "第43章"
let essentialsChapter43Title = "第43章 カスタマイズされた SwiftUI ProgressView の作成"
let essentialsChapter43SubTitle = "第43章 カスタマイズされた SwiftUI ProgressView の作成"

//コード
let codeEssentials43 = """
struct Essentials43ContentsView: View {
    var body: some View {
        ScrollView{
            E43ProgressBarStandardView()
            E43ProgressBarCircularView()
            E43InterminateProgressView()
            E43CustomProgressView()
        }
        .safeAreaPadding()
    }
}

struct E43ProgressBarStandardView: View {
    @State private var progressValue: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(LinearProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
    }
}

struct E43ProgressBarCircularView: View {
    @State private var progressValue: Double = 0.0
    @State private var progressValue1: Double = 0.0
    @State private var progressValue2: Double = 0.0
    @State private var progressValue3: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(CircularProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
        VStack{
            ProgressView("進捗1:\\(Int(progressValue1))",value: progressValue1, total: 100)
                .padding()
            Slider(value: $progressValue1,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗2:\\(Int(progressValue2))",value: progressValue2, total: 10000)
                .padding()
            Slider(value: $progressValue2,in: 0...10000,step:200)
                .padding()
            ProgressView("進捗3:\\(Int(progressValue3))",value: progressValue3, total: 1000000)
                .padding()
            Slider(value: $progressValue3,in: 0...1000000,step:20000)
                .padding()
        }
        .progressViewStyle(CircularProgressViewStyle())
        .padding()
    }
}

struct E43InterminateProgressView:View {
    var body: some View {
        ProgressView("進捗")
    }
}

//【雛型】
struct E43CustomProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
        //自分で設定
    }
}

struct E43ShadowProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
            .tint(Color.red)
            .shadow(
                color: Color(red:0,green: 0.8,blue:0.1),
                radius: 6.0,
                x: 2.0,
                y: 2.0
            )
            .progressViewStyle(LinearProgressViewStyle())
    }
}

struct E43PercentProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        let percent = Int(configuration.fractionCompleted!*100)
        return Text("進捗:\\(percent)%完了")
    }
}

struct E43CircularPercentProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        let degrees = configuration.fractionCompleted!*360
        let percent = Int(configuration.fractionCompleted!*100)
        return VStack{
            E43CircleGraph(
                startAngle: .degrees(0),
                endAngle: .degrees(degrees)
            )
            .frame(width: 300,height: 300)
            .padding()
            Text("進捗:\\(percent)%完了")
        }
    }
}

struct E43CircleGraph: Shape {
    var startAngle: Angle
    var endAngle: Angle
    
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.addArc(
            center: CGPoint(x:rect.midX, y: rect.midY),
            radius: rect.width / 2,
            startAngle: startAngle,
            endAngle: endAngle,
            clockwise: true
        )
        return path.strokedPath(.init(lineWidth: 100,dash: [6,4]))
    }
}

struct E43CustomProgressView: View {
    @State private var progressValueShadow: Double = 0.0
    @State private var progressValuePercent: Double = 0.0
    @State private var progressValueCircle: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\\(Int(progressValueShadow))",value: progressValueShadow, total: 100)
                .progressViewStyle(E43ShadowProgressViewStyle())
                .padding()
            Slider(value: $progressValueShadow,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗:\\(Int(progressValuePercent))",value: progressValuePercent, total: 100)
                .progressViewStyle(E43PercentProgressViewStyle())
                .padding()
            Slider(value: $progressValuePercent,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗:\\(Int(progressValueCircle))",value: progressValueCircle, total: 100)
                .progressViewStyle(E43CircularPercentProgressViewStyle())
                .padding()
            Slider(value: $progressValueCircle,in: 0...100,step: 1)
                .padding()
        }
    }
}
"""

//ポイント
let pointEssentials43 = """
今回は特になし。
"""

//URL
let urlEssentials43 = "https://note.com/m_kakudo/n/nf0a7075ad6e9"

//ビュー管理構造体
struct ListiOSApp17DevelopmentEssentialsCh43: Identifiable {
    var id: Int
    var title: String
    var view: ViewEnumiOSApp17DevelopmentEssentialsCh43
}
//遷移先の画面を格納する列挙型
enum ViewEnumiOSApp17DevelopmentEssentialsCh43{
    case Sec1
}
//各項目に表示するリスト項目
let dataiOSApp17DevelopmentEssentialsCh43: [ListiOSApp17DevelopmentEssentialsCh43] = [
    ListiOSApp17DevelopmentEssentialsCh43(id: 1, title: essentialsChapter43SubTitle, view: .Sec1),
]
struct iOSApp17DevelopmentEssentialsCh43: View {
    var body: some View {
        VStack {
            Divider()
            List (dataiOSApp17DevelopmentEssentialsCh43) { data in
                self.containedViewiOSApp17DevelopmentEssentialsCh43(dataiOSApp17DevelopmentEssentialsCh43: data)
            }
            .edgesIgnoringSafeArea([.bottom])
        }
        .navigationTitle(essentialsChapter43NavigationTitle)
        .navigationBarTitleDisplayMode(.inline)
    }
    //タップ後に遷移先へ遷移させる関数
    func containedViewiOSApp17DevelopmentEssentialsCh43(dataiOSApp17DevelopmentEssentialsCh43: ListiOSApp17DevelopmentEssentialsCh43) -> AnyView {
        switch dataiOSApp17DevelopmentEssentialsCh43.view {
        case .Sec1:
            return AnyView(NavigationLink (destination: Essentials43()) {
                Text(dataiOSApp17DevelopmentEssentialsCh43.title)
            })
        }
    }
}
#Preview {
    iOSApp17DevelopmentEssentialsCh43()
}

struct Essentials43: View {
    var body: some View {
        VStack{
            TabView {
                Essentials43ContentsView()
                    .tabItem {
                        Image(systemName: contentsImageTab)
                        Text(contentsTextTab)
                    }
                Essentials43Code()
                    .tabItem {
                        Image(systemName: codeImageTab)
                        Text(codeTextTab)
                    }
                Essentials43Points()
                    .tabItem {
                        Image(systemName: pointImageTab)
                        Text(pointTextTab)
                    }
                Essentials43WEB()
                    .tabItem {
                        Image(systemName: webImageTab)
                        Text(webTextTab)
                    }
            }
        }
    }
}
#Preview {
    Essentials43()
}

struct Essentials43Code: View {
    var body: some View {
        ScrollView{
            Text(codeEssentials43)
        }
    }
}
#Preview {
    Essentials43Code()
}
struct Essentials43Points: View {
    var body: some View {
        ScrollView{
            Text(pointEssentials43)
        }
    }
}
#Preview {
    Essentials43Points()
}
struct Essentials43WebView: UIViewRepresentable {
    let searchURL: URL
    func makeUIView(context: Context) -> WKWebView {
        let view = WKWebView()
        let request = URLRequest(url: searchURL)
        view.load(request)
        return view
    }
    func updateUIView(_ uiView: WKWebView, context: Context) {
        
    }
}
struct Essentials43WEB: View {
    private var url:URL = URL(string: urlEssentials43)!
    var body: some View {Essentials43WebView(searchURL: url)
    }
}
#Preview {
    Essentials43WEB()
}

struct Essentials43ContentsView: View {
    var body: some View {
        ScrollView{
            E43ProgressBarStandardView()
            E43ProgressBarCircularView()
            E43InterminateProgressView()
            E43CustomProgressView()
        }
        .safeAreaPadding()
    }
}

struct E43ProgressBarStandardView: View {
    @State private var progressValue: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(LinearProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
    }
}

struct E43ProgressBarCircularView: View {
    @State private var progressValue: Double = 0.0
    @State private var progressValue1: Double = 0.0
    @State private var progressValue2: Double = 0.0
    @State private var progressValue3: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValue))",value: progressValue, total: 100)
                .progressViewStyle(CircularProgressViewStyle())
                .padding()
            Slider(value: $progressValue,in: 0...100,step: 0.1)
                .padding()
        }
        .padding()
        VStack{
            ProgressView("進捗1:\(Int(progressValue1))",value: progressValue1, total: 100)
                .padding()
            Slider(value: $progressValue1,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗2:\(Int(progressValue2))",value: progressValue2, total: 10000)
                .padding()
            Slider(value: $progressValue2,in: 0...10000,step:200)
                .padding()
            ProgressView("進捗3:\(Int(progressValue3))",value: progressValue3, total: 1000000)
                .padding()
            Slider(value: $progressValue3,in: 0...1000000,step:20000)
                .padding()
        }
        .progressViewStyle(CircularProgressViewStyle())
        .padding()
    }
}

struct E43InterminateProgressView:View {
    var body: some View {
        ProgressView("進捗")
    }
}

//【雛型】
struct E43CustomProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
        //自分で設定
    }
}

struct E43ShadowProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
            .tint(Color.red)
            .shadow(
                color: Color(red:0,green: 0.8,blue:0.1),
                radius: 6.0,
                x: 2.0,
                y: 2.0
            )
            .progressViewStyle(LinearProgressViewStyle())
    }
}

struct E43PercentProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        let percent = Int(configuration.fractionCompleted!*100)
        return Text("進捗:\(percent)%完了")
    }
}

struct E43CircularPercentProgressViewStyle: ProgressViewStyle{
    func makeBody(configuration: Configuration) -> some View {
        let degrees = configuration.fractionCompleted!*360
        let percent = Int(configuration.fractionCompleted!*100)
        return VStack{
            E43CircleGraph(
                startAngle: .degrees(0),
                endAngle: .degrees(degrees)
            )
            .frame(width: 300,height: 300)
            .padding()
            Text("進捗:\(percent)%完了")
        }
    }
}

struct E43CircleGraph: Shape {
    var startAngle: Angle
    var endAngle: Angle
    
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.addArc(
            center: CGPoint(x:rect.midX, y: rect.midY),
            radius: rect.width / 2,
            startAngle: startAngle,
            endAngle: endAngle,
            clockwise: true
        )
        return path.strokedPath(.init(lineWidth: 100,dash: [6,4]))
    }
}

struct E43CustomProgressView: View {
    @State private var progressValueShadow: Double = 0.0
    @State private var progressValuePercent: Double = 0.0
    @State private var progressValueCircle: Double = 0.0
    
    var body: some View {
        VStack{
            ProgressView("進捗:\(Int(progressValueShadow))",value: progressValueShadow, total: 100)
                .progressViewStyle(E43ShadowProgressViewStyle())
                .padding()
            Slider(value: $progressValueShadow,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗:\(Int(progressValuePercent))",value: progressValuePercent, total: 100)
                .progressViewStyle(E43PercentProgressViewStyle())
                .padding()
            Slider(value: $progressValuePercent,in: 0...100,step: 1)
                .padding()
            ProgressView("進捗:\(Int(progressValueCircle))",value: progressValueCircle, total: 100)
                .progressViewStyle(E43CircularPercentProgressViewStyle())
                .padding()
            Slider(value: $progressValueCircle,in: 0...100,step: 1)
                .padding()
        }
    }
}

#Preview {
    Essentials43ContentsView()
}

◾️EssentialsMenu.swift

//フレームワーク
import SwiftUI
import WebKit

//ビュー管理構造体
struct ListiOSApp17DevelopmentEssentials: Identifiable {
    var id: Int
    var title: String
    var view: ViewEnumiOSApp17DevelopmentEssentials
}
//遷移先の画面を格納する列挙型
enum ViewEnumiOSApp17DevelopmentEssentials {
    case Ch1
    //じっくり13で追加
    case Ch2
    //じっくり14で追加
    case Ch3
    //じっくり15で追加
    case Ch4
    //じっくり16で追加
    case Ch5
    //じっくり17で追加
    case Ch6
    //じっくり18で追加
    case Ch7
    //じっくり19で追加
    case Ch8
    //じっくり20、21で追加
    case Ch9
    //じっくり22、23で追加
    case Ch10
    //じっくり24で追加
    case Ch11
    //じっくり25で追加
    case Ch12
    //じっくり26で追加
    case Ch13
    //じっくり27,28で追加
    case Ch14
    //じっくり29で追加
    case Ch15
    //じっくり31で追加
    case Ch16
    //じっくり32で追加
    case Ch17
    //じっくり33で追加
    case Ch18
    //じっくり34で追加
    case Ch19
    //じっくり35で追加
    case Ch20
    //じっくり36で追加
    case Ch21
    //じっくり37で追加
    case Ch22
    //じっくり40で追加
    case Ch23
    //じっくり41で追加
    case Ch24
    //じっくり43で追加
    case Ch25
    //じっくり44で追加
    case Ch26
    //じっくり45で追加
    case Ch27
    //じっくり46で追加
    case Ch28
    //じっくり47で追加
    case Ch29
    //じっくり48で追加
    case Ch30
    //じっくり49で追加
    case Ch31
    //じっくり50で追加
    case Ch32
    //じっくり51で追加
    case Ch33
    //じっくり52で追加
    case Ch34
    //じっくり53で追加
    case Ch35
    //じっくり54で追加
    case Ch36
    //じっくり55で追加
    case Ch37
    //じっくり56で追加
    case Ch38
    //じっくり57で追加
    case Ch39
    //じっくり58で追加
    case Ch40
    //じっくり59で追加
    case Ch41
    //じっくり60で追加
    case Ch42
    //じっくり61で追加
    case Ch43
}
//各項目に表示する文字列
let dataiOSApp17DevelopmentEssentials: [ListiOSApp17DevelopmentEssentials] = [
    ListiOSApp17DevelopmentEssentials(id: 1, title: essentialsChapter1Title, view: .Ch1),
    //じっくり13で追加
    ListiOSApp17DevelopmentEssentials(id: 2, title: essentialsChapter2Title, view: .Ch2),
    //じっくり13で追加
    ListiOSApp17DevelopmentEssentials(id: 3, title: essentialsChapter3Title, view: .Ch3),
    //じっくり15で追加
    ListiOSApp17DevelopmentEssentials(id: 4, title: essentialsChapter4Title, view: .Ch4),
    //じっくり16で追加
    ListiOSApp17DevelopmentEssentials(id: 5, title: essentialsChapter5Title, view: .Ch5),
    //じっくり17で追加
    ListiOSApp17DevelopmentEssentials(id: 6, title: essentialsChapter6Title, view: .Ch6),
    //じっくり18で追加
    ListiOSApp17DevelopmentEssentials(id: 7, title: essentialsChapter7Title, view: .Ch7),
    //じっくり19で追加
    ListiOSApp17DevelopmentEssentials(id: 8, title: essentialsChapter8Title, view: .Ch8),
    //じっくり20、21で追加
    ListiOSApp17DevelopmentEssentials(id: 9, title: essentialsChapter9Title, view: .Ch9),
    //じっくり22、23で追加
    ListiOSApp17DevelopmentEssentials(id: 10, title: essentialsChapter10Title, view: .Ch10),
    //じっくり24で追加
    ListiOSApp17DevelopmentEssentials(id: 11, title: essentialsChapter11Title, view: .Ch11),
    //じっくり25で追加
    ListiOSApp17DevelopmentEssentials(id: 12, title: essentialsChapter12Title, view: .Ch12),
    //じっくり26で追加
    ListiOSApp17DevelopmentEssentials(id: 13, title: essentialsChapter13Title, view: .Ch13),
    //じっくり27,28で追加
    ListiOSApp17DevelopmentEssentials(id: 14, title: essentialsChapter14Title, view: .Ch14),
    //じっくり29で追加
    ListiOSApp17DevelopmentEssentials(id: 15, title: essentialsChapter15Title, view: .Ch15),
    //じっくり31で追加
    ListiOSApp17DevelopmentEssentials(id: 16, title: essentialsChapter16Title, view: .Ch16),
    //じっくり32で追加
    ListiOSApp17DevelopmentEssentials(id: 17, title: essentialsChapter17Title, view: .Ch17),
    //じっくり33で追加
    ListiOSApp17DevelopmentEssentials(id: 18, title: essentialsChapter18Title, view: .Ch18),
    //じっくり34で追加
    ListiOSApp17DevelopmentEssentials(id: 19, title: essentialsChapter19Title, view: .Ch19),
    //じっくり35で追加
    ListiOSApp17DevelopmentEssentials(id: 20, title: essentialsChapter20Title, view: .Ch20),
    //じっくり36で追加
    ListiOSApp17DevelopmentEssentials(id: 21, title: essentialsChapter21Title, view: .Ch21),
    //じっくり37で追加
    ListiOSApp17DevelopmentEssentials(id: 22, title: essentialsChapter22Title, view: .Ch22),
    //じっくり40で追加
    ListiOSApp17DevelopmentEssentials(id: 23, title: essentialsChapter23Title, view: .Ch23),
    //じっくり41で追加
    ListiOSApp17DevelopmentEssentials(id: 24, title: essentialsChapter24Title, view: .Ch24),
    //じっくり43で追加
    ListiOSApp17DevelopmentEssentials(id: 25, title: essentialsChapter25Title, view: .Ch25),
    //じっくり44で追加
    ListiOSApp17DevelopmentEssentials(id: 26, title: essentialsChapter26Title, view: .Ch26),
    //じっくり45で追加
    ListiOSApp17DevelopmentEssentials(id: 27, title: essentialsChapter27Title, view: .Ch27),
    //じっくり46で追加
    ListiOSApp17DevelopmentEssentials(id: 28, title: essentialsChapter28Title, view: .Ch28),
    //じっくり47で追加
    ListiOSApp17DevelopmentEssentials(id: 29, title: essentialsChapter29Title, view: .Ch29),
    //じっくり48で追加
    ListiOSApp17DevelopmentEssentials(id: 30, title: essentialsChapter30Title, view: .Ch30),
    //じっくり49で追加
    ListiOSApp17DevelopmentEssentials(id: 31, title: essentialsChapter31Title, view: .Ch31),
    //じっくり50で追加
    ListiOSApp17DevelopmentEssentials(id: 32, title: essentialsChapter32Title, view: .Ch32),
    //じっくり51で追加
    ListiOSApp17DevelopmentEssentials(id: 33, title: essentialsChapter33Title, view: .Ch33),
    //じっくり52で追加
    ListiOSApp17DevelopmentEssentials(id: 34, title: essentialsChapter34Title, view: .Ch34),
    //じっくり53で追加
    ListiOSApp17DevelopmentEssentials(id: 35, title: essentialsChapter35Title, view: .Ch35),
    //じっくり54で追加
    ListiOSApp17DevelopmentEssentials(id: 36, title: essentialsChapter36Title, view: .Ch36),
    //じっくり55で追加
    ListiOSApp17DevelopmentEssentials(id: 37, title: essentialsChapter37Title, view: .Ch37),
    //じっくり56で追加
    ListiOSApp17DevelopmentEssentials(id: 38, title: essentialsChapter38Title, view: .Ch38),
    //じっくり57で追加
    ListiOSApp17DevelopmentEssentials(id: 39, title: essentialsChapter39Title, view: .Ch39),
    //じっくり58で追加
    ListiOSApp17DevelopmentEssentials(id: 40, title: essentialsChapter40Title, view: .Ch40),
    //じっくり59で追加
    ListiOSApp17DevelopmentEssentials(id: 41, title: essentialsChapter41Title, view: .Ch41),
    //じっくり60で追加
    ListiOSApp17DevelopmentEssentials(id: 42, title: essentialsChapter42Title, view: .Ch42),
    //じっくり61で追加
    ListiOSApp17DevelopmentEssentials(id: 43, title: essentialsChapter43Title, view: .Ch43),
]

struct iOSApp17DevelopmentEssentials: View {
    var body: some View {
        VStack {
            Divider()
            List (dataiOSApp17DevelopmentEssentials) { data in
                self.containedViewiOSApp17DevelopmentEssentials(dataiOSApp17DevelopmentEssentials: data)
            }
            .edgesIgnoringSafeArea([.bottom])
        }
        .navigationTitle("iOS開発の章目次")
        .navigationBarTitleDisplayMode(.inline)
    }
    //タップ後に遷移先へ遷移させる関数
    func containedViewiOSApp17DevelopmentEssentials(dataiOSApp17DevelopmentEssentials: ListiOSApp17DevelopmentEssentials) -> AnyView {
        switch dataiOSApp17DevelopmentEssentials.view {
        case .Ch1:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh1()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり13で追加
        case .Ch2:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh2()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり13で追加
        case .Ch3:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh3()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり15で追加
        case .Ch4:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh4()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり16で追加
        case .Ch5:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh5()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり17で追加
        case .Ch6:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh6()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり18で追加
        case .Ch7:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh7()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり19で追加
        case .Ch8:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh8()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり20、21で追加
        case .Ch9:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh9()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり22、23で追加
        case .Ch10:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh10()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり24で追加
        case .Ch11:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh11()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり25で追加
        case .Ch12:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh12()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり26で追加
        case .Ch13:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh13()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり27,28で追加
        case .Ch14:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh14()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり29で追加
        case .Ch15:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh15()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり31で追加
        case .Ch16:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh16()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり32で追加
        case .Ch17:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh17()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり33で追加
        case .Ch18:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh18()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり34で追加
        case .Ch19:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh19()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり35で追加
        case .Ch20:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh20()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり36で追加
        case .Ch21:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh21()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり37で追加
        case .Ch22:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh22()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり40で追加
        case .Ch23:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh23()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり41で追加
        case .Ch24:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh24()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり43で追加
        case .Ch25:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh25()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり44で追加
        case .Ch26:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh26()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり45で追加
        case .Ch27:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh27()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり46で追加
        case .Ch28:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh28()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり47で追加
        case .Ch29:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh29()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり48で追加
        case .Ch30:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh30()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり49で追加
        case .Ch31:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh31()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり50で追加
        case .Ch32:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh32()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり51で追加
        case .Ch33:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh33()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり52で追加
        case .Ch34:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh34()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり53で追加
        case .Ch35:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh35()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり54で追加
        case .Ch36:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh36()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり55で追加
        case .Ch37:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh37()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり56で追加
        case .Ch38:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh38()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり57で追加
        case .Ch39:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh39()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり58で追加
        case .Ch40:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh40()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり59で追加
        case .Ch41:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh41()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり60で追加
        case .Ch42:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh42()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり61で追加
        case .Ch43:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh43()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
        }
    }
}

#Preview {
    iOSApp17DevelopmentEssentials()
}

以上。

さてと、今日の読売新聞と文藝春秋読もうっと。
みなさんも良きお盆休みを〜〜〜


この記事が気に入ったらサポートをしてみませんか?