我想更改 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 https://i.stack.imgur.com/a4mqP.png
提前致谢!
我正在使用这个库https://github.com/CEWendel/SWTableViewCell 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;
}
希望它能帮助你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)