相关疑难解决方法(0)

如何使单元格具有渐变背景?

我在视图控制器上插入了一个表格视图,我想知道如何为表格视图中的单元格提供渐变背景?我可以单独编辑每个单元格,为每个单元格赋予不同的颜色渐变背景吗?例如,每个单元格都标记在trainingLevels数组中的一个索引之后,我如何才能使每个单元格具有不同的颜色渐变背景?

这是我的代码:

import UIKit

 class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var trainingLevels = ["Ball Handling", "Shooting", "Defense", "Advanced Drills", "Vertimax Drills", "Full Workouts", "BHB Products"]


@IBOutlet weak var tableView: TableView!


func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    cell.backgroundColor = UIColor.clear
}

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{

    return trainingLevels.count
}


public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "bell")
    cell.textLabel?.text …
Run Code Online (Sandbox Code Playgroud)

gradient cell viewcontroller swift

2
推荐指数
2
解决办法
7929
查看次数

标签 统计

cell ×1

gradient ×1

swift ×1

viewcontroller ×1