系統(tǒng)的刪除按鈕是紅色的缕题,而往往公司想要一個(gè)和主色調(diào)一樣的顏色截歉。這就需要自己再定義了。
代碼如下
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}
//改變刪除按鈕的樣式
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction * delect = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
UIAlertController *alertView = [UIAlertController alertControllerWithTitle:@"提示" message:@"刪除這條消息" preferredStyle:UIAlertControllerStyleAlert];
[alertView addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
#pragma mark 測(cè)試階段先這樣寫烟零,之后再改
[_list removeObjectAtIndex:indexPath.row];
[_MainTab reloadData];
}]];
[self presentViewController:alertView animated:true completion:nil];
}];
delect.backgroundColor = XHRGBA(91, 178, 187, 1);
return @[delect];
}
當(dāng)然也可以實(shí)現(xiàn)多個(gè)按鈕的效果瘪松,比如置頂/收藏/刪除。因?yàn)榉祷氐氖菙?shù)組锨阿。