iOS中的uitableview删除按钮图像 [英] uitableview delete button image in iOS
本文介绍了iOS中的uitableview删除按钮图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改uitableview单元的滑动按钮图像.我已经搜索过,但没有得到想要的结果.我使用了以下代码:
I want to change swipe button image of uitableview cell. I have searched for it but I am not get desired result. I have used this code:
- (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中实现此目的.
But this is not working in iOS 9. Please suggest me how to achieve this in iOS 9.
如果我使用此代码,则它可以正常工作,但图像设置不正确:
If I used this code then its working but image is not set properly:
[[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];
}
> 提前谢谢!
推荐答案
我正在使用此库 https://github.com/CEWendel/SWTableViewCell 以便在滑动按钮上显示图像.
I am using this library https://github.com/CEWendel/SWTableViewCell to display image on swipe button.
#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;
}
希望它会对您有所帮助.
Hope it will help you.
这篇关于iOS中的uitableview删除按钮图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文