tora-muscle / 1weekPDCA

このアプリは一週間をより有意義なものにするために一週間単位で生活を振り返ることができるアプリです
MIT License
0 stars 0 forks source link

✨ Bottom bar 実装 #3

Closed tora-muscle closed 1 year ago

tora-muscle commented 1 year ago

🎫 関連課題

✨ 実現したいこと

🚩 やらないこと

🔀 達成条件

👀 備考

スクリーンショット 2023-02-02 10 08 43

tora-muscle commented 1 year ago

🎨 デザイン変更

変更点

スクリーンショット 2023-02-04 11 34 58

tora-muscle commented 1 year ago

🔧 要件追加

tora-muscle commented 1 year ago

🗒 メモ : flutterのように個別のWidgetとしてBottom bar を切り出したい

SwiftUIでボトムバーを再利用するには、以下のように自分自身を表示するViewを構造体で作成して、他の画面で使用する。

struct BottomBar: View {
    var body: some View {
        // Bottom Bar Content Here
    }
}

別の画面では、次のようにBottomBarを使用することができる。

struct SomeView: View {
    var body: some View {
        VStack {
            // Some View Content Here
            BottomBar()
        }
    }
}
tora-muscle commented 1 year ago

🗒 メモ : Font.systemの引数でどんなデザインになるか

https://capibara1969.com/1981/ この記事がわかりやすかった🙌

tora-muscle commented 1 year ago

🗒 .renderingMode(.template)を定義した際、先に.frame()すると怒られる件について

.renderingMode(.template)はサイズが指定されていない画像に対して変更を加える。 よって、.renderingMode(.template)より先に.frame(width: 30.0)などを定義すると

Cannot infer contextual base in reference to member 'template'
Value of type 'some View' has no member 'renderingMode'

と怒られる

self.tabItems[index].view
                    .tabItem {
                        Image(systemName: self.tabItems[index].image)
                            .renderingMode(.template)
                            .foregroundColor(self.selectedIndex == index ? Color("UIColorGreen") : Color("UIColorGray"))
                            .padding(.bottom, 30.0)
                            .frame(width: 30.0)
                    }
tora-muscle commented 1 year ago

🗒 タブバーの色を変更する方法

struct BottomBar: View {

    // ボトムバーの色を定義
    init() {
        UITabBar.appearance().backgroundColor = .darkGray
        UITabBar.appearance().unselectedItemTintColor = .gray
        }

参考文献 ▼ https://tech.amefure.com/swift-tabview 他にも「バッジ表示方法」など、詳しくまとまっているから今後助けてもらえそう!

⚠️ 追記 ⚠️

tora-muscle commented 1 year ago

👀 備考

https://github.com/k-saito-en/1weekPDCA/issues/3#issuecomment-1420244965

残件ありにつき、本課題はまだ進行中とする なお、作業ブランチは #8 時に作成したブランチとする

tora-muscle commented 1 year ago

👀 残件

- [ ] figma更新

tora-muscle commented 1 year ago

🗒 カスタムタブバーの実装方法

▼ モデル

struct BottomBarItem {
    let image: String
    let view: AnyView
}

▼ 中身

let bottomBarItems = [
        BottomBarItem(image: "graduationcap.fill", view: AnyView(ActView())),
        BottomBarItem(image: "square.fill", view: AnyView(PlanDoView())),
        BottomBarItem(image: "checkmark.circle.fill", view: AnyView(CheckView()))
    ]
タブバーの実装 ```swift //MARK: ボトムバーの実装 struct BottomBar: View { // タブの選択値と初期値. @State private var selected = 0 var body: some View { ZStack { // 背景色. Color.backGroundColorGray.ignoresSafeArea() // メイン画面部分はTabViewで定義. TabView(selection: $selected) { ForEach(0 ..< 3) { index in bottomBarItems[index].view .tag(index) } } // PageTabスタイルを利用する(インジケータは非表示). .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never)) VStack { Spacer(minLength: 0) // タブビュー部分. HStack { ForEach(0 ..< 3) { index in Image(systemName: bottomBarItems[index].image) .resizable() .aspectRatio(contentMode: .fit) .frame(width: 20, height: 20) .onTapGesture { self.selected = index } .foregroundColor(self.selected == index ? Color.black : Color.gray) } } .padding(.vertical, 10.0) .padding(.horizontal, 20.0) .background(Color.white.clipShape(Capsule())) .shadow(color: Color.black.opacity(0.3), radius: 5, x: -5, y: 5) } } } } ```

▼ 参考記事

tora-muscle commented 1 year ago

👀 残件