Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    Working with @Generable and @Guide in Foundation Models

    July 18, 2025

    Navigating the labyrinth of forks

    July 18, 2025

    OpenAI unveils ‘ChatGPT agent’ that gives ChatGPT its own computer to autonomously use your email and web apps, download and create files for you

    July 18, 2025
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»ios – How to style NavigationLink when pressed?
    iOS Development

    ios – How to style NavigationLink when pressed?

    big tee tech hubBy big tee tech hubMarch 16, 2025003 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    ios – How to style NavigationLink when pressed?
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    I’m a beginner and i’ve been trying to build a safari app extension as my first project.
    I’m trying to customize the look of NavigationLink rows inside a list when pressed.

    Right now, pressing each row looks like this:

    enter image description here

    It gets that dark gray highlight, and i want to change it to something smoother.

    The code for that view is divided in two files, the HomeView and the FolderRowView. I’ll add both for context:

    // HomeView snippet
    
        var body: some View {
            NavigationStack {
                VStack(alignment: .leading, spacing: 8) {
                    
                    HStack {
                        Text("Explore")
                            .font(.title2)
                        
                        Spacer()
                        
                        SortButton(isAscending: $isAscending) // Now properly updates sorting
                    }
                    
                    SearchBar(text: $searchText)
                        .padding(.vertical, 2)
    
                    //below is the list with the NavigationLink
                    List(filteredFolders) { folder in
                        NavigationLink(destination: DummyFolderDetailView(folder: folder)) {
                            FolderRowView(folder: folder)
                        }
                    }
                    .clipShape(RoundedRectangle(cornerRadius: 8))
                    .navigationTitle("Folders")
                }
            }
        }
    
    // Component FolderRowView
    
    struct FolderRowView: View {
        let folder: Folder
        @State private var isHovering = false
        
        var body: some View {
            HStack {
                // Folder Icon
                Image(systemName: "folder.fill")
                    .resizable()
                    .scaledToFit()
                    .frame(width: 18, height: 18)
                    .foregroundStyle(.gray)
                
                Spacer()
                
                // Folder Name
                Text(folder.name)
                    .font(.body)
                    .frame(maxWidth: .infinity, alignment: .leading)
                
                // Chevron Icon
                Image(systemName: "chevron.right")
                    .foregroundColor(.gray)
            }
            .padding(.vertical, 6)
            .padding(.horizontal, 10) // Added horizontal padding for space around content
            .background(isHovering ? Color.gray.opacity(0.1) : Color.clear) // Optional background change on hover
            .scaleEffect(isHovering ? 1.05 : 1.0) // Zoom-in effect
            .cornerRadius(8)
            .animation(.easeInOut(duration: 0.2), value: isHovering) // Smooth animation
            .onHover { hovering in
                isHovering = hovering
            }
            .contextMenu { //(...)
    

    So as you can see i already successfully added on hover styling and animation to the rows by working inside the component file.
    I realize that customizing the on press style is a bit more complicated than that!

    I tried:

    • .onTapGesture with @State private var isPressed = false in the component file, which showed up on press correctly, but interfered with the NavigationLink click in a way the action was no longer actioning 🙂

    • Made a third component file CustomStyle containing view struct PressableStyle: ButtonStyle that was then added as a modifier to the NavigationLink as .buttonStyle(PressableStyle()) but it didn’t really do anything..

    • ChatGPT suggested i try creating a component view FolderRowLink that calls the FolderRowView, nests it inside a button, and embeds a hidden NavigationLink triggered by the button. Then in the HomeView i’d only have to call that FolderRowLink view in the list. I tried this but it has the same result as the first approach, where the new on press style shows up but clicking doesn’t action.


    I understand the highlight color applied by default in the on press is the accentColor, but i’ve ran into some issues with it where .foregroundStyle(.accent) calls my Assets.xcassets AccentColor, but .foregroundStyle(Color.accentColor) calls a dark gray (the one showing on press by default) and adding style modifiers to the NavigationLink doesn’t work either.

    Overall i guess i just want to know whether styling this is possible, and how do you guys do it?



    Source link

    iOS NavigationLink pressed style
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    Working with @Generable and @Guide in Foundation Models

    July 18, 2025

    Deep dive into Swift frameworks

    July 17, 2025

    Apple News+ launches clever new ‘Emoji Game’ for iOS 18.4 and later

    July 17, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Working with @Generable and @Guide in Foundation Models

    July 18, 2025

    Navigating the labyrinth of forks

    July 18, 2025

    OpenAI unveils ‘ChatGPT agent’ that gives ChatGPT its own computer to autonomously use your email and web apps, download and create files for you

    July 18, 2025

    Big milestone for the future of quantum computing.

    July 18, 2025
    Advertisement
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    Working with @Generable and @Guide in Foundation Models

    July 18, 2025

    Navigating the labyrinth of forks

    July 18, 2025

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2025 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.