Wednesday, May 29, 2024
HomeiOS Developmentswiftui - Annoying white hole in iOS code and tint gone improper

swiftui – Annoying white hole in iOS code and tint gone improper


The concept was to place a set header that is still for each tabview, however, there may be an annoying white area between header and picture that eradicating all of the Spacer () doesn’t remedy.

Annoying White House

And likewise, there was a progress bar which confirmed blue for each loading tab view (they’re principally webpages within the tab views) however, after making an attempt to vary the “Chosen tabitem” to white with .tint(.white) the blue progress bar has additionally turned white.
White Progress Bar

Can anybody, please, assist me? I’m fairly determined at this level.

I’ve tried eradicating the Spacer () but it surely didn’t assist. And taking part in round with other ways to tint chosen tab merchandise didn’t assist both.

Full code beneath:

//
//  ContentView.swift
//  Code Historical past
//
//  Created by JESUS' Seraphel  on 16/01/2024.
//
import WebKit
import SwiftUI
import SwiftData
import AVKit
import MessageUI
import UniformTypeIdentifiers


//Pink Color for Tabbar

extension UIColor {
    
    static let bubbleGumPink = UIColor(pink: 8.9, inexperienced: 0.7, blue: 0.9, alpha: 2) }

//Most important View

struct ContentView: View {
    let background = Picture("Header")
    let mainColor = Colour.white
    let textColor = Colour.white
    

    
    @State non-public var showingPopover = false
    @State non-public var sendEmail = false
    let constants = Constants.shared
    
    //Community Verify
    @EnvironmentObject var networkMonitor: NetworkMonitor 
    
    //Copy Hyperlink
    var tackle: String = "Hello! Be part of me on the HSM app with this hyperlink: https://apps.apple.com/gh/app/heaven-seekers-ministry/id1605769086"
    
    @State non-public var isCopied: Bool = false
    
    
    var physique: some View {
        NavigationStack{
            ScrollView {
                //HeaderImage
                
                Picture("Header")
                    .body(width: 400, top: 170)
                    .ignoresSafeArea()
                    .edgesIgnoringSafeArea(.all)
                
                    .body(top: 150)
                
                
                
                ZStack {
                    //HeaderText
                    HStack {
                        VStack (alignment: .main, spacing: 0) {
                            
                            
                            
                            Spacer()
                            Spacer()
                            Spacer()
                            Spacer()
                            Textual content("HEAVEN SEEKERS MIN.")
                                .font(
                                    Font.customized("Avenir Subsequent", dimension: 22))
                                .daring()
                            
                            
                            Textual content("The Undiluted Gospel...")
                                .font(
                                    Font.customized("Avenir Subsequent", dimension: 19))
                            
                            
                            Spacer()
                            Spacer()
                            Spacer()
                            
                            VStack (spacing: -20){
                                HStack{
                                    //Buttons
                                    
                                    //Invite
                                    Button(motion: {showingPopover = true}) {
                                        Picture(systemName: "particular person.badge.plus.fill")
                                        Textual content("Invite         ")
                                            .padding(.horizontal)
                                            .font(
                                                Font.customized("Avenir Subsequent", dimension: 17))
                                        
                                        //Invite Popover
                                            .popover(isPresented:
                                                        $showingPopover) {
                                                ZStack{
                                                    Colour.purple
                                                        .ignoresSafeArea()
                                                    
                                                    HStack {
                                                        VStack {
                                                            Listing {
                                                                
                                                                //Head Textual content
                                                                
                                                                Textual content("Invite Members")
                                                                    .font( Font.customized("Avenir Subsequent", dimension: 23))
                                                                    .daring()
                                                                    .foregroundColor(Colour.white)
                                                                    .listRowSeparator(.hidden)
                                                                    .listRowBackground(Colour.purple)
                                                                
                                                                //Sub Textual content
                                                                
                                                                Textual content("Invite folks to hitch you within the app!")
                                                                    .font(Font.customized("Avenir Subsequent", dimension: 15))
                                                                    .italic()
                                                                    .foregroundColor(Colour.white)
                                                                    .listRowSeparatorTint(.white)
                                                                    .listRowBackground(Colour.purple)
                                                                
                                                                //Share Hyperlink
                                                                
                                                                ShareLink(merchandise: URL(string: "https://apps.apple.com/gh/app/heaven-seekers-ministry/id1605769086")!) {
                                                                    Label("Share by way of social & extra", systemImage: "sq..and.arrow.up") }
                                                                .listRowBackground(Colour.purple)
                                                                .daring()
                                                                .font(Font.customized("Avenir Subsequent", dimension: 20))
                                                                
                                                                
                                                                //Copy Hyperlink
                                                                
                                                                //Popup Message
                                                                if isCopied {
                                                                                                                                                Textual content("Copied Efficiently!")
                                                                             .daring()
                                                                                .font(Font.customized("Avenir Subsequent", dimension: 20))
                                                                                .foregroundColor(.white)
                                                                                .body(width: 440, top: 70)
                                                                                .foregroundColor(.white)
                                                                                .background(Colour.purple)
                                                                                .shadow(radius: 4)
                                                                        
                                                                }
                                                                
                                                                
                                                                //Copy Code
                                                                
                                                Textual content("(Picture(systemName: "hyperlink.circle.fill"))    Copy Hyperlink")
                                                                .listRowBackground(Colour.purple)
                                                                .daring()
                                                                .font(Font.customized("Avenir Subsequent", dimension: 20))
                                                                .onTapGesture {
                                                                    let clipboard = UIPasteboard.normal
                                                                    clipboard.setValue(tackle, forPasteboardType: UTType.plainText.identifier)
                                                                    isCopied = true
                                                                    DispatchQueue.primary.asyncAfter(wallDeadline: .now() + 3) {
                                                                        withAnimation {
                                                                            isCopied = false
                                                                        }
                                                                    }
                                                                }
                                                                
                                                            }
                                                            
                                                            .background(.purple).scrollContentBackground(.hidden)
                                                            
                                                            .foregroundColor(Colour.white)
                                                            .presentationDetents([.height(250)])
                                                            .presentationBackground(Colour.purple)
                                                            
                                                        }
                                                        
                                                        
                                                        
                                                    }
                                                }
                                                Spacer()
                                                
                                            }
                                        
                                        
                                    }
                                    
                                    
                                    .padding()
                                    .foregroundColor(Colour.purple)
                                    .background(
                                        RoundedRectangle(cornerRadius: 100)
                                            .stroke(Colour.purple, lineWidth: 2)
                                    )
                                    .cornerRadius(100)
                                    
                                    
                                    //Contact Us
                                    Button(motion: {sendEmail.toggle()}) {
                                        Picture(systemName: "envelope.open")
                                        Textual content("Contact Us")
                                            .padding(.horizontal)
                                            .font(
                                                Font.customized("Avenir Subsequent", dimension: 17))
                                    }
                                    .sheet(isPresented: $sendEmail) {
                                        MailView(content material: constants.contentPreText, to: constants.e mail,topic: constants.topic)
                                    }
                                    
                                    .padding()
                                    .foregroundColor(Colour.white)
                                    .background(Colour.purple)
                                    .cornerRadius(100)
                                    
                                }
                            }
                            Spacer()
                            Spacer()
                            
                            
                            
                            
                        }
                        .body(maxWidth: .infinity)
                        
                        .background(
                            RoundedRectangle(cornerRadius: 20)
                                .foregroundColor(.white).shadow(radius: 4))
                        .offset(x: 0, y:0)
                        
                        
                        Spacer()
                        
                    }
                    //Brand
                    .overlay( Picture("brand")
                        .resizable()
                        .body(width: 70, top: 70)
                        .padding()
                        .shadow(radius: 4)
                        .offset(x:-150, y:-110))
                    
                    
                }
            }
            
            //TabView Pages
            
            TabView {
                if networkMonitor.isConnected {
                    
                    //HomeView
                    HomeView()
                        .tabItem {
                            Label("Residence", systemImage: "home.circle")
                        }
                        
                    
                    //MediaView
                    MediaView()
                        .tabItem {
                            Label("Media", systemImage: "television.and.mediabox")
                        }
                    
                    //VideosView
                    VideosView()
                        .tabItem {
                            Label("Movies", systemImage: "video")
                        }
                    
                    
                    //ContactView
                    ContactView()
                        .tabItem {
                            Label("Contact", systemImage: "particular person.crop.circle.fill")
                        }
                    
                    
                }
                    else {
                        // In any other case, present one thing else
                        NoNetworkView() }}
            .onAppear() {
                
                UITabBar.look().backgroundColor = .purple
                UITabBar.look().unselectedItemTintColor = .bubbleGumPink

            }
            
            
            .tint(.white)
            
            
            
                .ignoresSafeArea()
            }
        }

       
    }

    
    
    
    
    
    //Preview
    
    struct Preview: PreviewProvider {
        static var previews: some View {
            ContentView()
                .environmentObject(NetworkMonitor())
            
        }
    }
    
    



//Webpage View

struct Webview: UIViewControllerRepresentable {
    let url: URL
    func makeUIViewController(context: Context) -> WebviewController {
        let webviewController = WebviewController()
        let request = URLRequest(url: self.url, cachePolicy: .returnCacheDataElseLoad)
        webviewController.webview.load(request)
        return webviewController
    }
    func updateUIViewController(_ webviewController: WebviewController, context: Context) {
        //
    }
}

class WebviewController: UIViewController, WKNavigationDelegate {
    lazy var webview: WKWebView = WKWebView()
    lazy var progressbar: UIProgressView = UIProgressView()
    deinit {
        self.webview.removeObserver(self, forKeyPath: "estimatedProgress")
        self.webview.scrollView.removeObserver(self, forKeyPath: "contentOffset")
    }
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        self.webview.navigationDelegate = self
        self.view.addSubview(self.webview)
        self.webview.body = self.view.body
        self.webview.translatesAutoresizingMaskIntoConstraints = false
        self.view.addConstraints([
            self.webview.topAnchor.constraint(equalTo: self.view.topAnchor),
            self.webview.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
            self.webview.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
            self.webview.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
        ])
        self.webview.addSubview(self.progressbar)
        self.setProgressBarPosition()
        webview.scrollView.addObserver(self, forKeyPath: "contentOffset", choices: .new, context: nil)
        self.progressbar.progress = 0.1
        webview.addObserver(self, forKeyPath: "estimatedProgress", choices: .new, context: nil)
    }
    func setProgressBarPosition() {
        self.progressbar.translatesAutoresizingMaskIntoConstraints = false
        self.webview.removeConstraints(self.webview.constraints)
        self.webview.addConstraints([
            self.progressbar.topAnchor.constraint(equalTo: self.webview.topAnchor, constant: self.webview.scrollView.contentOffset.y * -1),
            self.progressbar.leadingAnchor.constraint(equalTo: self.webview.leadingAnchor),
            self.progressbar.trailingAnchor.constraint(equalTo: self.webview.trailingAnchor),
        ])
    }
    // MARK: - Internet view progress
    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        change keyPath {
        case "estimatedProgress":
            if self.webview.estimatedProgress >= 1.0 {
                UIView.animate(withDuration: 0.3, animations: { () in
                    self.progressbar.alpha = 0.0
                }, completion: { completed in
                    self.progressbar.setProgress(0.0, animated: false)
                })
            } else {
                self.progressbar.isHidden = false
                self.progressbar.alpha = 1.0
                progressbar.setProgress(Float(self.webview.estimatedProgress), animated: true)
            }
        case "contentOffset":
            self.setProgressBarPosition()
        default:
            tremendous.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
        }
    }
}




//Community Verify

class NetworkMonitor: ObservableObject {
    non-public let networkMonitor = NWPathMonitor()
    non-public let workerQueue = DispatchQueue(label: "Monitor")
    var isConnected = false

    init() {
        networkMonitor.pathUpdateHandler = { path in
            self.isConnected = path.standing == .happy
            Job {
                await MainActor.run {
                    self.objectWillChange.ship()
                }
            }
        }
        networkMonitor.begin(queue: workerQueue)
    }
}


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments