【问题标题】:Add downward-pointing arrow in table view cell在表格视图单元格中添加向下箭头
【发布时间】:2019-08-06 20:37:51
【问题描述】:

我正在寻找一种方法来实现底部箭头,就像在 Apple 的 Activity 应用中一样。

我在电池配件类型中找不到类似的东西。

    cell.accessoryType = UITableViewCell.AccessoryType.none
    cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
    cell.accessoryType = UITableViewCell.AccessoryType.detailDisclosureButton
    cell.accessoryType = UITableViewCell.AccessoryType.checkmark
    cell.accessoryType = UITableViewCell.AccessoryType.detailButton

我知道我可以在那里插入UIImage,但也许有更好的解决方案来解决这个问题。我在其他单元格中使用了默认的披露指示符,因此我想在我的应用中保持相同的设计。

【问题讨论】:

    标签: ios uitableview cocoa-touch


    【解决方案1】:

    正确的解决方案是添加自定义图像资源并将 UIImage 放置在单元格的 accessoryView 中。

    一个 hacky 解决方案 - 可能不起作用 - 您可以尝试将 accessoryType 设置为 disclosureIndicator 然后尝试通过将 transform 设置为 CGAffineTransform(rotationAngle: .pi / 2) 来旋转 accessoryView

    【讨论】:

    • myCell.accessoryType = .disclosureIndicator myCell..accessoryView?.transform = CGAffineTransform(rotationAngle: .pi/2) ,这不起作用。我不知道,但是当我尝试打印 acessoryView 边界时,我得到了 nil
    【解决方案2】:

    我认为你不能旋转默认的disclosureIndicator

    常规解决方案来了。

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .subtitle, reuseIdentifier: nil) // dequeue as necessary
        cell.backgroundColor = .lightGray
        cell.textLabel?.text = "\(indexPath.row)"
        let downArrow = UIImage(named: "down_arrow")
        cell.accessoryView = UIImageView(image: downArrow)
        return cell
    }
    

    这句话末尾的白色向下箭头图像。

    【讨论】:

    • 感谢另一个解决方案。还有一件事,你知道 accesoryType 是什么尺寸吗?
    • 不确定,可能需要调整到合适为止
    猜你喜欢
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多