我想更改uitableview单元格的滑动按钮图像。我已经搜索过但我没有得到理想的结果。我使用过这段代码:
- (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];
}
] 1
提前致谢!
答案 0 :(得分:4)
我正在使用此库https://github.com/CEWendel/SWTableViewCell在滑动按钮上显示图像。
#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;
}
希望它会对你有所帮助。
答案 1 :(得分:0)
我不会去寻找任何类型的黑客,比如在小区的层次结构中找到子视图。我要么自己实施刷卡(它不那么难)或使用一些吊舱。见这个:
答案 2 :(得分:-2)
这不是你要求的,但你可以用废纸篓表情符号替换“删除”文本。
func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
return ""
}