iTableView在iOS中删除按钮图像
我想更改uitableview单元格的滑动按钮图像。我已经找过了,但没有得到想要的结果。我使用了以下代码:iTableView在iOS中删除按钮图像,ios,objective-c,uitableview,ios9.1,Ios,Objective C,Uitableview,Ios9.1,我想更改uitableview单元格的滑动按钮图像。我已经找过了,但没有得到想要的结果。我使用了以下代码: - (void)willTransitionToState:(UITableViewCellStateMask)state{ [super willTransitionToState:state]; if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellSt
- (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];
}
}
}
}
但这在iOS 9中不起作用。请建议我如何在iOS 9中实现这一点
如果我使用此代码,则其工作但图像设置不正确:
[[UIButton
appearanceWhenContainedIn:[TableViewCell class], nil]
setImage:[UIImage imageNamed:@"Delete-notification.png"] forState:UIControlStateNormal];
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button 1");
}];
return @[button];
}
]
提前谢谢 我不会去做任何类似于在单元格层次结构的某个地方找到子视图的黑客行为。我要么自己实现刷卡(没那么难),要么使用一些pod。看看这个: 我正在使用此库在滑动按钮上显示图像
#import "SWTableViewCell.h"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SWTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"idTipsCell"];
[cell setLeftUtilityButtons:[self leftButtonsWithColor:tipsData.color accessibilityValue:(tipsData.isLiked) ? @"1":@"0"] WithButtonWidth:80.0];
cell.delegate = self;
return cell;
}
- (NSArray *)leftButtonsWithColor:(UIColor*)color accessibilityValue:(NSString*)accessibilityValue {
NSMutableArray *leftUtilityButtons = [NSMutableArray new];
[leftUtilityButtons sw_addUtilityButtonWithColor:color icon:[UIImage imageNamed:@"img_like"] accessibilityValue:accessibilityValue];
[leftUtilityButtons sw_addUtilityButtonWithColor:color icon:[UIImage imageNamed:@"img_share"] accessibilityValue:@"shareButton"];
return leftUtilityButtons;
}
希望它能对您有所帮助。这并不是您真正想要的,但您可以用废纸篓表情符号替换“删除”文本
func tableView(tableView:UITableView,titleForDeleteConfirmationButtonFrrowatineXPath-indexPath:NSIndexPath)->字符串?{
return“我可以使用UITableViewRowAction,但我想知道如何在“删除”按钮上设置图像。@Feminabrambhatt我也使用过,但不起作用:(有趣的方法))