0

私のアプリではTableViewCell、カードのように表示するようにカスタマイズしました。UITableViewRowActionsこれらのセルのカスタムも実装しました。ただし、セルをフローティングカードのように見せるためにレイヤーを追加したため、アクションは奇妙に見えます。

これが 私のcellForRowAt関数のコードです。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "someCell", for: indexPath) as! CustomCell
        cell.delegate = self

        cell.backgroundColor = .clear
        cell.contentView.backgroundColor = .clear

        let whiteRoundedView: UIView = UIView(frame: CGRect(x: 10, y: 8, width: self.view.frame.size.width - 20, height: cell.frame.size.height - 20))
        whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.9])
        whiteRoundedView.layer.masksToBounds = false
        whiteRoundedView.layer.cornerRadius = 2.0
        whiteRoundedView.layer.shadowOffset = CGSize(width: -1, height: 1)
        whiteRoundedView.layer.shadowOpacity = 0.2
        cell.contentView.addSubview(whiteRoundedView)
        cell.contentView.sendSubview(toBack: whiteRoundedView)

        cell.updateCell()
        return cell
    }

そして私のUITableViewRowAction機能。警告: このSwipeCellKitリポジトリを使用しています

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
        if orientation == .left {
            guard isSwipeRightEnabled else { return nil }
            let completeAction = SwipeAction(style: .default, title: "Complete") { (action, index) in
                print("complete!")

            }
            completeAction.backgroundColor = .green
            return [completeAction]
        } else {
            let deleteAction = SwipeAction(style: .destructive, title: "Delete") { (action, index) in
                print("delete")
            }
            return [deleteAction]
        }
    }

UITableViewRowActionセルの型に合わせてサイズを変更する方法はありますか?

4

3 に答える 3

2

2019 年にまだ解決策を探している人のために、目に見えない Unicode 文字を使用して幅を設定できます。

UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"\u2060\t\t\t\u2060" handler: [self handler]];
于 2019-03-04T03:21:58.137 に答える
0

フレームワークにいくつかの変更を加えることなく、現時点では不可能です。

表示される直前にSwipeTableViewCellDelegateそれぞれを公開するいくつかのメソッドを追加する計画があり、スワイプが引き続き発生します。UIButtonレイアウトを実現するのに十分な柔軟性が得られると思います。

当面は、自分のフォークでこれを行うのはそれほど難しくありません。具体的には、メソッドSwipeTableViewCell内のを見てください。スワイプサブクラスを含むプロパティを持つ をconfigureActionView作成します。それらをアプリに公開するだけです。SwipeActionsViewbuttonsUIButton

于 2017-02-24T20:41:27.953 に答える