Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stretchable header with text #60

Open
minyilee95 opened this issue Jul 26, 2024 · 0 comments
Open

Stretchable header with text #60

minyilee95 opened this issue Jul 26, 2024 · 0 comments

Comments

@minyilee95
Copy link

Hi,

I'm trying to implement a stretchy header where the header is an image with text overlayed. If I use .allowsHeaderGrowth() I get this behavior:
Simulator Screen Recording - iPhone 15 Pro - 2024-07-26 at 17 28 59

I'm trying to get something like this:
Simulator Screen Recording - iPhone 15 Pro - 2024-07-26 at 17 27 34

Where just the image stretches but the text doesn't change size.

Is it possible to implement this with your package?

Thanks so much!

This is the code I'm using for the 'correct' stretchy header if that's helpful:

import SwiftUI

struct StretchyHeaderWorking: View {
    var body: some View {
        ScrollView {
            VStack {
                HeaderView()
                LazyVStack {
                    ForEach(1...100, id: \.self) {
                        Divider()
                        Text("\($0)").frame(maxWidth: .infinity)
                    }
                }
            }
        }
        
        
    }}

    @ViewBuilder
    func HeaderView()->some View{
        GeometryReader{proxy in
            let minY = proxy.frame(in: .named("SCROLL")).minY
            let size = proxy.size
            let height = (size.height + minY)
            
            Image("header")
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: size.width,height: height > 0 ? height : 0,alignment: .top)
                .overlay(content: {
                    ZStack(alignment: .bottom) {
                        VStack(alignment: .leading, spacing: 5) {
                            Spacer()
                            HStack(alignment: .bottom, spacing: 10) {
                                Text("HEADER")
                                    .font(.largeTitle.bold())
                                    .foregroundStyle(.white)
                            }
                            
                        }
                        .padding(.horizontal)
                        .padding(.bottom,25)
                        .frame(maxWidth: .infinity,alignment: .leading)
                        .offset(x: 0, y: -101)
                    }
                })
                .cornerRadius(0)
                .offset(y: -minY)
        }
        .frame(height: 400)
        .toolbarBackground(.hidden)
        .navigationBarBackButtonHidden(true)
        
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant