如果你重写了tableView: commitEditingStyle: forRowAtIndexPath:函数,那么UITableViewCell在非编辑状态从右向左侧滑,右边会出现红色的“删除”按钮。但如何像微信一样定制button呢?
iOS8以前
在iOS8以前(应该猜到了在iOS8开始后会有更直接的办法,之后会说到),Apple没有提供直接修改button的API,我们必须用很纠结的方法来进行设置。
1.cell的subviews结构
先看看iOS7时cell的subviews结构:
- UITableViewCell
- UITableViewCellScrollView
- UITableViewCellDeleteConfirmationView
- UITableViewCellDeleteConfirmationButton
- UITableViewCellContentView
- UITableViewCellSeparatorView
找到了这个DeleteConfirmationButton,我们只需要把它替换成我们自己的buttonMenu就行了。
2.实现方法
在iOS7.1之前,DeleteConfirmationButton一直存在,可以重写layoutSubviews,在这个函数内获取DeleteConfirmationButton。
但是从iOS7.1开始,cell为editing状态时DeleteConfirma