如何在Swift的表格视图单元格中更改默认的删除button?
我想在Swift中实现这个代码。 我从这些问题中得到了Objective-C中的以下代码:
在刷行或单击编辑button时,更改UITableViewCell中默认的红色删除button的颜色
自定义UITableView中的删除button
- (void)willTransitionToState:(UITableViewCellStateMask)state{ [super willTransitionToState:state]; if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) { for (UIView *subview in self.subviews) { if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) { UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)]; [deleteBtn setImage:[UIImage imageNamed:@"delete.png"]]; [[subview.subviews objectAtIndex:0] addSubview:deleteBtn]; [deleteBtn release]; } } } }
我不知道如何在Swift中实现这个方法。 任何人都可以帮我吗?
我正在使用Xcode 7.3 Beta。
swift tableview委托有新的方法。 试试这可能会解决你的问题。
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]{ let ackAction:UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Himanshu", handler: myFunction) ackAction.backgroundColor = UIColor.orangeColor() return [moreAction] }
现在你甚至可以修改你的删除function
UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)]; [deleteBtn setImage:[UIImage imageNamed:@"delete.png"]];
在这里你看到你的buttondelete.png你需要改变你的图像delete.png。 以后会改变的。
[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
在这里你也可以改变尺寸
谢谢