iOS Development

ios – The way to delete UINavigationController’s area programmatically utilizing Swift

Spread the love


Once I redirect to a web page from UINavigationController, the vacation spot web page exhibits the contents of the Navigation Bar with extra space above than anticipated. How can I repair this example?

MainTabController

//
//  HomeTabBarController.swift
//  MatchVocab
//
//  Created by Yasin Kabak on 13.01.2024.
//

import UIKit

ultimate class MainTabBarViewController: UITabBarController{
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        
   
        view.backgroundColor = .white
        
        let homeVC = UINavigationController(rootViewController: HomeScreen())
        let searchVC = UINavigationController(rootViewController: SearchScreen())
        let favouriteVC = UINavigationController(rootViewController: FavouriteScreen())
        
        homeVC.tabBarItem = UITabBarItem(title: "dwelling", picture: UIImage(systemName: "home"), tag: 0)
        searchVC.tabBarItem = UITabBarItem(title: "search", picture: UIImage(systemName: "magnifyingglass"), tag: 1)
        favouriteVC.tabBarItem = UITabBarItem(title: "favorite", picture: UIImage(systemName: "coronary heart"), tag: 2)
        setViewControllers([homeVC,searchVC,favouriteVC], animated: true)
        
        
        
    }
    
}

HomeScreen:

import UIKit

enum Sections: Int {
    case Dwelling, Favorite, Search
}

protocol HomeScreenInterface: AnyObject {
    func configureVC()
    func configureNavigationBar()
    func configureTableView()
}

ultimate class HomeScreen: UIViewController {
    var viewModel = HomeViewModel()
    var tableView: UITableView!
    
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        viewModel.view = self
        viewModel.viewDidLoad()
        viewModel.fetchWordFromCoreData()
    }
}

extension HomeScreen: HomeScreenInterface {
    func configureVC() {
        view.backgroundColor = .systemBackground.withAlphaComponent(0.8)
        overrideUserInterfaceStyle = .mild
    }

    func configureTableView() {
        tableView = UITableView(body: .zero)
        view.addSubview(tableView)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(WordCell.self, forCellReuseIdentifier: WordCell.identifier)
        tableView.translatesAutoresizingMaskIntoConstraints = false
        tableView.backgroundColor = .systemBackground.withAlphaComponent(0.8)
        NSLayoutConstraint.activate([
            tableView.topAnchor.constraint(equalTo: view.topAnchor),
            tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
        ])
    }

    func configureNavigationBar() {
        navigationController?.navigationBar.prefersLargeTitles = true
        navigationItem.title = "Phrases"
        navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.systemBlue]
        navigationItem.rightBarButtonItem = UIBarButtonItem(picture: UIImage(systemName: "plus"), type: .plain, goal: self, motion: #selector(addWord))
        navigationItem.leftBarButtonItem = UIBarButtonItem(picture: UIImage(systemName: "magnifyingglass"), type: .plain, goal: self, motion: #selector(searchWord))
    }
}

extension HomeScreen: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return CGFloat.getScreenHeight() * 0.05
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
        return viewModel.phrases.depend
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: WordCell.identifier, for: indexPath) as! WordCell
        cell.setCell(mannequin: viewModel.phrases[indexPath.row])
        return cell
    }
}

extension HomeScreen {
    @objc func addWord() {
        let vc = UINavigationController(rootViewController: CreateScreen())
        vc.modalPresentationStyle = .fullScreen
        current(vc, animated: true)
    }

    @objc func searchWord() {
        let vc = SearchScreen()
        vc.modalPresentationStyle = .fullScreen
        current(vc, animated: true)
    }
}

pictures:

dwelling display screen web page

I attempted to delete the secure space in UINavigationController however I failed

Leave a Reply

Your email address will not be published. Required fields are marked *