【问题标题】:Colours different when testing against iPad and iPhone针对 iPad 和 iPhone 进行测试时颜色不同
【发布时间】:2015-06-17 15:51:32
【问题描述】:

我正在使用自动布局和通用设备制作 iOS 应用。除了一件事,颜色之外,这两种设备都可以正常工作。我直接从情节提要中更改颜色,所以我不知道为什么会发生这种情况:

这是同一视图的 iPhone 屏幕截图和 iPad 屏幕截图:

我有一些颜色在情节提要中设置为默认值,但即使设置了它们也不完美:

【问题讨论】:

    标签: ios iphone ipad swift uistoryboard


    【解决方案1】:

    要为UITableView 设置背景颜色,您必须创建一个背景视图并将其分配给tableView.backgroundView 属性。因此,在您的 viewController 的 viewDidLoad 中:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        let backgroundView = UIView()
        backgroundView.backgroundColor = UIColor.redColor()  // just to demonstrate        
        self.tableView.backgroundView = backgroundView
    }
    

    【讨论】:

    • 谢谢,我会测试一下。但为什么这在 iPhone 上有效,而在 iPad 上无效?
    • 我不能说你得到的效果是什么原因,需要看你的故事板。上面的代码应该可以正常工作。
    • 这有帮助,尽管我从情节提要中更改了它,但它不适用于附件。
    【解决方案2】:

    为了使其适用于任何单元格、附件视图,您必须在控制器中添加此功能:

    override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        cell.backgroundColor = UIColor(red: 44/255, green: 42/255, blue: 43/255, alpha: 1)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多