[英]How to add a delete button to Collection View Cell in Swift?
[英]How to change the default delete button in a table view cell in Swift?
我想在Swift中实现这个代码。 我在Objective-C中从这些问题中获得了以下代码:
在滑动行或单击编辑按钮时,更改UITableViewCell中默认红色删除按钮的颜色
- (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, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?{
let ackAction = UITableViewRowAction(style: .default, title: "Himanshu", handler: myFunction)
ackAction.backgroundColor = UIColor.orange
return [ackAction]
}
现在您甚至可以修改删除功能
UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
[deleteBtn setImage:[UIImage imageNamed:@"delete.png"]];
在这里,您可以看到您的按钮delete.png,您需要在图片中更改delete.png。 以后会改变。
[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
此外,您还可以更改尺寸
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.