You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iPhone 12 Pro Max模拟器中UITableViewCell背景填充不全求助

问题描述

在不同iPhone机型上调试应用时,发现仅在iPhone 12 Pro Max模拟器中使用UITableViewController时,UITableViewCell的背景无法完全填充,其他机型(包括iPhone 11 Pro Max)均运行正常。由于使用UITableViewController无法添加约束,特此寻求解决建议。

相关代码

单元格与控制器代码

import UIKit
import FirebaseAuth
class MenuCustomCellController: UITableViewCell {
    
    @IBOutlet weak var imEvento: UIImageView!  
    @IBOutlet weak var txtNombreEvento: UILabel!   
    @IBOutlet weak var txtFechaEvento: UILabel!   
    @IBOutlet weak var txtEstadoEvento: UILabel!
}
class MenuInicialTableController: UITableViewController {
   
    @IBOutlet weak var celdaUsuarios: UITableViewCell!
    @IBOutlet weak var celdaEventos: UITableViewCell! 
    @IBOutlet weak var celdaBuscarEventos: UITableViewCell!
    @IBOutlet weak var celdaGraficos: UITableViewCell!
    @IBOutlet weak var celdaCerrar: UITableViewCell!   
    @IBOutlet weak var celdaAyuda: UITableViewCell!
    
   
    override func viewWillAppear(_ animated: Bool) {
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(MenuInicialTableController.tapFunction))
                celdaCerrar.isUserInteractionEnabled = true
                celdaCerrar.addGestureRecognizer(tap)
        let background = UIView()
        tableView.backgroundView = background
        tableView.backgroundView?.aplicarFondoDegradado()
        tableView.layer.borderWidth = 2
        tableView.layer.borderColor =  UIColor.white.cgColor
        tableView.layer.cornerRadius = 10
        celdaUsuarios.layer.borderWidth = 1
        celdaUsuarios.layer.borderColor =  UIColor.white.cgColor
        celdaUsuarios.layer.cornerRadius = 10
        celdaUsuarios.contentView.aplicarFondoMenuUsuarios()
        celdaEventos.layer.borderWidth = 1
        celdaEventos.layer.borderColor =  UIColor.white.cgColor
        celdaEventos.layer.cornerRadius = 10
        celdaEventos.contentView.aplicarFondoMenuEventos()
        celdaGraficos.layer.borderWidth = 1
        celdaGraficos.layer.borderColor =  UIColor.white.cgColor
        celdaGraficos.layer.cornerRadius = 10
        celdaGraficos.contentView.aplicarFondoMenuEventos()
        celdaCerrar.layer.borderWidth = 1
        celdaCerrar.layer.borderColor =  UIColor.white.cgColor
        celdaCerrar.layer.cornerRadius = 10
        celdaCerrar.contentView.aplicarFondoMenuUsuarios()
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "MENÚ PRINCIPAL"
        self.navigationItem.setHidesBackButton(true, animated: true)
        
    }

  
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    //Dos filas por sección
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    @objc
     func tapFunction(sender:UITapGestureRecognizer) {
         exit(0)
     }
}

渐变背景扩展代码

func aplicarFondoMenuUsuarios() {
        let colorInicio =  UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0).cgColor
        let colorFin = UIColor(red: 0/255, green: 190/255, blue: 219/255, alpha: 1.0).cgColor
        if let gradientLayer = layer.sublayers?.first as? CAGradientLayer {
                gradientLayer.colors = [colorInicio,colorFin]
        }
        else{
            let gradientLayer = CAGradientLayer()
            gradientLayer.colors = [colorInicio, colorFin]
            gradientLayer.startPoint = CGPoint(x: 0, y: 0.50)
            gradientLayer.endPoint = CGPoint(x: 0.50, y: 1.00)
            gradientLayer.frame = self.bounds
            self.layer.insertSublayer(gradientLayer, at:0)
            
        }
}

func aplicarFondoMenuEventos() {
        let colorInicio =  UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0).cgColor
        let colorFin = UIColor(red: 15/255, green: 0/255, blue: 219/255, alpha: 1.0).cgColor
        if let gradientLayer = layer.sublayers?.first as? CAGradientLayer {
                gradientLayer.colors = [colorInicio,colorFin]
        }
        else{
            let gradientLayer = CAGradientLayer()
            gradientLayer.colors = [colorInicio, colorFin]
            gradientLayer.startPoint = CGPoint(x: 0, y: 0.50)
            gradientLayer.endPoint = CGPoint(x: 0.50, y: 1.00)
            gradientLayer.frame = self.bounds
            self.layer.insertSublayer(gradientLayer, at:0)
        }
    }
问题截图

iPhone 12 Pro Max中UITableViewCell背景未完全填充截图


内容的提问来源于stack exchange,提问作者Monrac

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 09:50:15