菜鸟教程小白 发表于 2022-12-11 20:01:19

ios - 自定义 UITableViewCell 中的默认删除按钮和图标


                                            <p><p>我正在尝试更改默认按钮以删除表格 View 中的一行(当用户向左滑动时)。
<a href="/image/FiYgH.png" rel="noreferrer noopener nofollow">Changing the height of the default confirmation delete button</a> </p>

<p>同时我想在进入编辑模式时在单元格左侧添加自定义图像...
[更改进入编辑模式删除时的默认图标<a href="/image/rjSiu.png" rel="noreferrer noopener nofollow">2</a> </p>

<p>我的代码中包含:</p>

<pre><code>func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -&gt; Bool {
    return true
}

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
}

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -&gt; ? {
    let delete = UITableViewRowAction(style: .destructive, title: &#34;\u{267A}\n Delete&#34;) { (action, indexPath) in
      tableView.isEditing = false
      print(&#34;delete&#34;)
      // delete item at indexPath
    }

    return
}
</code></pre>

<p>是否可以更改确认删除按钮的高度并为左侧图标添加自定义图像?</p>

<p>谢谢!
:)</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您需要将 UIImage 设置为 UITableViewRowAction 的 backgroundColor。</p>

<pre><code>let someAction = UITableViewRowAction(style: .Default, title: &#34;&#34;) { value in
      println(&#34;button did tapped!&#34;)
    }
    someAction.backgroundColor = UIColor(patternImage: UIImage(named: &#34;myImage&#34;)!)
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 自定义 UITableViewCell 中的默认删除按钮和图标,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44882478/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44882478/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 自定义 UITableViewCell 中的默认删除按钮和图标