No Tab View Header Background Color in Landscape Mode

I am having trouble with app tab view headers. The app contains four tabs with each tab header containing the tab name with a colored background that may be viewed in either portrait or landscape mode.

The first tab is used for transaction data entry and is different from the other three tabs with a Save button at the right end of the header and also has a Done button for description and money keyboards.

In portrait mode all four tabs correctly display the title and background color. In landscape mode, the transaction entry tab displays the title and Save button but there is no background color. The other three tabs correctly display the titles with background color.

I removed the portrait / landscape logic to see if I have a bug in the landscape logic but there was no change in behavior. I also created this cutdown demo with no change observed in landscape transaction entry tab.

I didn’t include all demo tab views in the code below, but you can copy TotalsTabView and change the name for the missing tabs. Likewise I didn’t include all transaction entry views such as categories, description, and money since they all are simple text views.

Create transaction entry view

struct EntryTabView: View {

    enum Field: Hashable {
        case ckDsc
        case ckAmt
    }
    @FocusState private var myFocus: Field?

    var body: some View {

        GeometryReader { g in
            VStack {

                ZStack (alignment: .top) {

                    if g.size.height > g.size.width {  // portrait?
                        Color(.green)
                            .frame(height: g.safeAreaInsets.top * 1.9, alignment: .top)
                            .ignoresSafeArea()

                    } else {  // landscape
                        Color(.green)
                            .frame(height: g.safeAreaInsets.top * 0.14, alignment: .top)
                            .ignoresSafeArea()
                    }
                    HStack {
                        VStack (alignment: .leading) {
                            Text("Expense Entry")
                                .font(.title)
                                .bold()
                                .kerning(1.5)
                                .padding(.leading, 10)
                                .frame(maxWidth: .infinity, alignment: .leading)
                        }
                        Spacer()

                        Button {
                            myFocus = nil
                            //self.saveButton()   // button pressed

                        } label: {
                            Text("Save")
                                .bold()
                                .padding(.trailing, 10)
                                .tint(.blue)
                        }
                       // .disabled(moneyS.isEmpty)
                    }
                }

                Form {
                    GetDate()
                        .padding(.bottom, 10)
                    GetPaymentType()
                        .padding(.bottom, 10)
                    GetCategory()
                        .padding(.bottom, 10)
                    GetDescription()
                        .padding(.bottom, 10)
                    GetMoney()
                }
            }
            .toolbar {
                ToolbarItemGroup(placement: .keyboard) {
                    Spacer()
                    Button("Done")
                    {
                        myFocus = nil
                    }
                }
            }
        }
    }
}
struct ContentView: View {

    var body: some View {

        NavigationStack {
            VStack {
                TabView () {

                    EntryTabView()
                        .tabItem {
                            Label("Expense Entry", systemImage: "entry.lever.keypad")
                        }
                        .tag(0)

                    TotalsTabView()
                        .tabItem {
                            Label("Totals", systemImage: "t.circle.fill")

                        }
                        .tag(1)

                    HistoryTabView()
                        .tabItem {
                            Label("History", systemImage: "clock.arrow.circlepath")
                        }
                        .tag(2)

                    MenuTabView()
                        .tabItem {
                            Label("More", systemImage: "ellipsis")
                        }
                        .tag(3)
                }
            }
            .tint(.blue)
            .symbolRenderingMode(.hierarchical)
            .symbolVariant(.fill)
        }
    }
}

Structure used to create tab view title headers (portrait / landscape and difference
size iPhones


struct DrawTabTitleBox: View {

    var g: GeometryProxy
    var title: String

    var body: some View {

        ZStack (alignment: .top) {
            if g.size.height > g.size.width {  // portrait

                if g.size.width < 380 {  // mini?
                    Color(.green)
                        .frame(height: g.safeAreaInsets.top * 1.9, alignment: .top)
                        .ignoresSafeArea()

                    VStack (alignment: .leading) {
                        Text(title)
                            .font(.title)
                            .bold()
                            .kerning(1.5)
                            .padding(.leading, 10)
                            .frame(maxWidth: .infinity, alignment: .leading)
                    }

                } else {       // pro max
                    Color(.green)
                        .frame(height: g.safeAreaInsets.top * 1.65, alignment: .top)
                        .ignoresSafeArea()

                    VStack (alignment: .leading) {
                        Text(title)
                            .font(.title)
                            .bold()
                            .kerning(1.5)
                            .padding(.leading, 10)
                            .frame(maxWidth: .infinity, alignment: .leading)
                    }
                }
            } else { // landscape

                if g.size.width < 720 {
                    Color(.green)
                        .ignoresSafeArea()
                        .frame(height: g.size.height * 0.14)

                    VStack (alignment: .leading) {
                        Text(title)
                            .font(.title)
                            .bold()
                            .kerning(1.5)
                            .padding(.top, 11)
                            .padding(.leading, 10)
                            .frame(maxWidth: .infinity, alignment: .leading)
                    }
                } else {

                    Color(.green)
                        .ignoresSafeArea()
                        .frame(height: g.size.height * 0.126)

                    VStack (alignment: .leading) {
                        Text(title)
                            .font(.title)
                            .bold()
                            .kerning(1.5)
                            .padding(.top, 11)
                            .padding(.leading, 10)
                            .frame(maxWidth: .infinity, alignment: .leading)

                    }
                }
            }
        }
    }
}

Typical transaction entry dummy code


struct GetDate: View {

    var body: some View {

        Text("Get Date")
    }
}

Method used to create tabview headers except for transaction entry tab


struct TotalsTabView: View {
    var body: some View {

        GeometryReader { g in
            VStack (alignment: .leading, spacing: 0) {

                DrawTabTitleBox(g: g, title: "Totals")

                Text("Totals View")
                    .frame(maxWidth: .infinity, alignment: .center)
            }
        }
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật