- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
YFAdddressOfNationModel *model=_arrAddress[indexPath.row];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
DLog(@"点击了删除");
[self alert:@"确定要删除收货地址吗?" confirm:@"确定删除" cancel:@"取消" completion:^{
//删除地址
NSDictionary *para = @{@"application":@"DeleteExpressAddress.Req",
@"id":model.idAddress
};
[self.request requestWithDictionary:para completion:^(BOOL success, id responseData) {
if (success) {
[self showHud:@"删除成功"];
[_arrAddress removeObjectAtIndex:indexPath.row];
[_mTableView reloadData];
}
}];
}];
}];
UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"设为默认" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
DLog(@"点击了设置默认");
NSDictionary *para = @{@"application":@"UpdateExpressAddress.Req",
@"userid":[USER_DEFAULT objectForKey:kUserId],
@"username":model.username,
@"telephone":model.telephone,
@"delocation":model.delocation,
@"deaddress":model.deaddress,
@"design":@"1",
@"id":model.idAddress
};
[self.request requestWithDictionary:para completion:^(BOOL success, id responseData) {
if (success) {
// model.design=@"1";
// [_mTableView reloadData];
// YFShippingAddressListCell* cell = [tableView cellForRowAtIndexPath:indexPath];
// if (cell.leftBtnInstance.constant>=25) {
// isFirst=YES;
// }
// else{
// isFirst=NO;
// }
_currentIndex=0;
_isFrom=@"default";
[self getAddressList:@"默认"];
}
}];
}];
改背景颜色 直接设置
editAction.backgroundColor = RGB(239, 239, 239);
// editAction.backgroundColor=[UIColor lightGrayColor];
// [editAction setValue:[UIColor whiteColor] forKey:@"titleTextColor"];
改按钮颜色 需要这么设置(如果有多个的话) ,单独改一个按钮标题颜色 [[UIButton appearance] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (@available(iOS 11.0,*)) {
for (UIView * lview in tableView.subviews) {
if ([lview isKindOfClass:NSClassFromString(@"UISwipeActionPullView")]){
// for (UIView * subcaceView in lview.subviews) {
//这里是单独的取到 第一个 来改颜色
if ([lview.subviews[0] isKindOfClass:NSClassFromString(@"UISwipeActionStandardButton")]) {
UIButton *btn=(UIButton *)lview.subviews[0];
[btn setTitleColor:Black1 forState:UIControlStateNormal];
}
// }
}
}
}
});
return @[deleteAction, editAction];
}