tableView のセルで、次の Swift コードを使用してグラデーションを定義しようとしています。
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:UITableViewCell = self.tableView?.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.backgroundColor=UIColor.clearColor()
let gradient : CAGradientLayer = CAGradientLayer()
var arrayColors:Array<AnyObject> = [UIColor.blackColor().CGColor, UIColor.whiteColor().CGColor]
gradient.colors=arrayColors
gradient.frame = cell.bounds
cell.layer.insertSublayer(gradient, atIndex: UInt32(indexPath.row))
return cell
}
ビューが最初に読み込まれると、すべてのセルの背景が白くなります。また、上下にスクロールすると、一部のコンテンツのセルが消え (タイトルとサブタイトル)、グラデーションが最終的にこれらのセルに表示されます (ランダムに、他の一部のセルは白い背景のままになります)。このキャストに関連しています - > UInt32(indexPath.row) ?