'Fix sidemenu bar logo display in swift

the swift code below allows you to view a side menu my problem is this, the first element of the menu is an image (attached) now the problem lies in the fact that in the image there is a space to the left of the screen, what I want to do is remove the space so that the image is flush with the screen, and bring the top image flush with the iPhone, the result I want to obtain is the one in figure 2, as I do this?

Image image 2 Swift Code:

protocol MenuControllerDelegate {
    func didSelectMenuItem(named: SideMenuItem)
}

enum SideMenuItem: String, CaseIterable {
    //DA NASCONDERE PRIMA VOCE MENU - FUNZIONALE PER BANNER HOMEPAGE
    case header = "Sito Web SynergyO2"
    //BLOCCO 1 - INTRO
    case home = "SynergyO2 - SO2 Business"
    //BLOCCO 2 - SCOPRI SYNERGY O2
    case sito = "Sito SynergyO2"
    case prodotti = "Prodotti"
    case blog = "Blog"
    //BLOCCO 3 - SCOPRI SO2BUSINESS
    case sitob = "Sito SO2 Business"
    case entra = "Entra nel Team"
    case blogb = "Business Blog"
    //BLOCCO 4 - STRUMENTI BUSINESS
    case bo = "Back Office"
    case business = "Sponsor Link"
    //BLOCCO 5 - CONTATTI
    case webinar = "Webinar"
    case circolari = "Circolari e Comunicazioni"
    case domande = "Fai una Domanda!"
    case seguici = "Seguici su"
}

class MenuController: UITableViewController {

    public var delegate: MenuControllerDelegate?

    private let menuItems: [SideMenuItem]
    private let color = UIColor(red: 33 / 255.0, green: 33 / 255.0, blue: 33 / 255.0, alpha: 1)

    init(with menuItems: [SideMenuItem]) {
        self.menuItems = menuItems

        super.init(nibName: nil, bundle: nil)
        tableView.register(UITableViewCell.self,
            forCellReuseIdentifier: "cell")
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.backgroundColor = UIColor.white
        view.backgroundColor = UIColor.white
        
    }

    // MENU

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return menuItems.count
    }

    //Recupero immagine da titolo
    func getimage(titolo: String) -> UIImage {
        var image: UIImage
        switch titolo {
        case "Scopri SynergyO2":
            image = UIImage(named: "sito")!
        case "Webinar":
            image = UIImage(named: "webinar")!
        case "Blog":
            image = UIImage(named: "blog")!
        case "Seguici su":
            image = UIImage(named: "seguici")!
        case "Fai una Domanda!":
            image = UIImage(named: "domanda")!
        case "Back Office":
            image = UIImage(named: "backoffice")!

        case "Circolari e Comunicazioni":
            image = UIImage(named: "circolari")!
        case "Area Business":
            image = UIImage(named: "area")!
        default:
            image = UIImage(named: "prodotti")!
        }
        return image
    }



    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = menuItems[indexPath.row].rawValue
        cell.textLabel?.textColor = .black
        cell.textLabel?.font = UIFont.systemFont(ofSize: 13.0)
        cell.backgroundColor = UIColor.white
        cell.contentView.backgroundColor = UIColor.white
        cell.imageView!.image = getimage(titolo: menuItems[indexPath.row].rawValue)

        if menuItems[indexPath.row].rawValue == "Sito Web SynergyO2" {
            cell.separatorInset = UIEdgeInsets.zero
            cell.layoutMargins = UIEdgeInsets.zero
            cell.preservesSuperviewLayoutMargins = false
            cell.frame = CGRect(x: 0, y: 0, width: 1600, height: 200)
            cell.contentView.backgroundColor = .white
            let imageName = "menulogo.png"
            let image = UIImage(named: imageName)
            cell.imageView?.image = image

        }

        return cell
    }

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.row == 0 {
            return 115
        } else {
            return 50
        }
    }


    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let selectedItem = menuItems[indexPath.row]
        delegate?.didSelectMenuItem(named: selectedItem)

    }
}


Solution 1:[1]

Have you tried to:

  • set self.automaticallyAdjustsScrollViewInsets = false on the table view controller? (i think it is deprecated and there is an alternaive call tho)
  • switch the table view to grouped/plain

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jalone