0
選擇背景大小我有這樣的代碼來獲取表格單元的UITableViewCell - 基於內容
func getCell(_ tableView: UITableView) -> UITableViewCell? {
var cell:UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: CELL_REUSE_ID)
if (cell == nil)
{
//init and configure the cell
cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: CELL_REUSE_ID)
let selectedView:UIView = UIView(frame: CGRect(x: 0, y: 0, width: cell!.frame.size.width, height: cell!.frame.size.height))
selectedView.backgroundColor = UIColor.black.withAlphaComponent(0.3)
let layer = selectedView.layer
layer.borderColor = UIColor.blue.cgColor
layer.borderWidth = getCellBorderWidth();
layer.cornerRadius = getCellCornerRadius();
layer.backgroundColor = UIColor.blue.cgColor
cell!.selectedBackgroundView = selectedView
}
return cell
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell:UITableViewCell? = getCell(tableView)
cell!.backgroundColor = UIColor.clear
cell!.textLabel!.textColor = UIColor.darkText
cell!.textLabel!.text = tableData[indexPath.row]
cell!.textLabel!.textAlignment = .right
cell!.textLabel!.numberOfLines = 1
cell!.textLabel!.adjustsFontSizeToFitWidth = true
return cell!
}
細胞與表中的代碼生成,沒有xibs。現在,如果我選擇單元格,背景將覆蓋整個表格的寬度。我如何爲某些單元格創建背景,這只是表格寬度的一半(或其他百分比)?