我将两种颜色的背景应用于tableview。当后台表加载数据表时,仅加载一个插入,不加载其他数据。因此,在运行后台功能时,它只会安装一个表行,而不会加载其他表行
extension UIView {
func setGradientBackground(sender: UITableViewController, colorOne: UIColor, colorTwo: UIColor) {
let gradientLayer = CAGradientLayer()
gradientLayer.frame = sender.view.bounds
gradientLayer.colors = [colorOne.cgColor, colorTwo.cgColor]
gradientLayer.locations = [0.0, 1.0]
gradientLayer.startPoint = CGPoint(x: 0.0, y: 1.0)
gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.0)
layer.insertSublayer(gradientLayer, at: 0)
} }
我在这里运行桌子
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! DeviceTableViewCell
cell.setGradientBackground(sender: self, colorOne: Colors.brightOrange, colorTwo: Colors.darkGrey)
let deviceItem: Device = items[indexPath.row]
cell.deviceItem = deviceItem
cell.title.text = deviceItem.title
cell.title1.text = deviceItem.places
cell.titlesaat.text = deviceItem.time
cell.button.isOn = deviceItem.state
tablerow = String (indexPath.row)
return cell
}