God*_*ike 3 cell tableview ios swift
我accessoryType对细胞有疑问.我正在使用带有disclosureIndicatoras 的单元格,accessoryType我想改变它的颜色,但我不能.有谁知道这是一个错误还是Apple迫使我使用灰色?其实我可以改变其他的颜色accessoryType.
我的代码看起来像这样:
let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath) as! customCell
cell.tintColor = UIColor.red
cell.accessoryType = .disclosureIndicator
Run Code Online (Sandbox Code Playgroud)
而我的箭仍然是灰色的.但如果我使用复选标记,accessoryType它会变成红色.
有没有办法解决这个问题,还是我必须使用彩色图像?
Bha*_*duk 11
你可以做这样的事情
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.tintColor = UIColor.white
let image = UIImage(named: "Arrow.png")
let checkmark = UIImageView(frame:CGRect(x:0, y:0, width:(image?.size.width)!, height:(image?.size.height)!));
checkmark.image = image
cell.accessoryView = checkmark
let object = objects[indexPath.row] as! NSDate
cell.textLabel!.text = object.description
return cell
}
Run Code Online (Sandbox Code Playgroud)
示例箭头图像
产量
小智 6
使用SF符号
let image = UIImage(systemName: "chevron.right")
let accessory = UIImageView(frame:CGRect(x:0, y:0, width:(image?.size.width)!, height:(image?.size.height)!))
accessory.image = image
// set the color here
accessory.tintColor = UIColor.white
cell.accessoryView = accessory
Run Code Online (Sandbox Code Playgroud)
为 Swift 4.2 更新并附有图像:
cell.accessoryType = .disclosureIndicator
cell.tintColor = .black
let image = UIImage(named:"disclosureArrow")?.withRenderingMode(.alwaysTemplate)
if let width = image?.size.width, let height = image?.size.height {
let disclosureImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
disclosureImageView.image = image
cell.accessoryView = disclosureImageView
}
Run Code Online (Sandbox Code Playgroud)
您可以使用的图像:
它可能是什么样子:
| 归档时间: |
|
| 查看次数: |
4337 次 |
| 最近记录: |