Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在测试iPad和iPhone时,颜色会有所不同_Ios_Iphone_Ipad_Swift_Uistoryboard - Fatal编程技术网

Ios 在测试iPad和iPhone时,颜色会有所不同

Ios 在测试iPad和iPhone时,颜色会有所不同,ios,iphone,ipad,swift,uistoryboard,Ios,Iphone,Ipad,Swift,Uistoryboard,我正在使用自动布局和通用设备制作iOS应用程序。除了一件事,颜色,这两种设备上的一切都很好。我直接从故事板上改变颜色,所以我不知道为什么会发生这种情况: 这是一个iPhone屏幕截图和一个相同视图的iPad屏幕截图: 我在故事板中设置了一些默认颜色,但即使设置了它们,也不是完美的: 要设置UITableView的背景色,必须创建背景视图并将其分配给tableView.backgroundView属性。因此,在viewController的viewDidLoad中: override func

我正在使用自动布局和通用设备制作iOS应用程序。除了一件事,颜色,这两种设备上的一切都很好。我直接从故事板上改变颜色,所以我不知道为什么会发生这种情况:

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

我在故事板中设置了一些默认颜色,但即使设置了它们,也不是完美的:


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

override func viewDidLoad() {
    super.viewDidLoad()

    let backgroundView = UIView()
    backgroundView.backgroundColor = UIColor.redColor()  // just to demonstrate        
    self.tableView.backgroundView = backgroundView
}
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)
}

为了使其与任何单元格(无论附件视图与否)一起工作,您必须在控制器中添加此功能:

override func viewDidLoad() {
    super.viewDidLoad()

    let backgroundView = UIView()
    backgroundView.backgroundColor = UIColor.redColor()  // just to demonstrate        
    self.tableView.backgroundView = backgroundView
}
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)
}

谢谢,我会测试的。但为什么这在iPhone上有效而在iPad上无效呢?我不能说是什么导致了你的效果,你需要看看你的故事板。上面的代码无论如何都应该可以工作。这很有帮助,尽管我在故事板上更改了它,但它对附件不起作用。