gpt4 book ai didi

ios - uitableview 删除 iOS 中的按钮图像

转载 作者:搜寻专家 更新时间:2023-10-30 20:15:17 24 4
gpt4 key购买 nike

我想更改 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];
}

like this ] 1

提前致谢!

最佳答案

我正在使用这个库 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;
}

希望对你有所帮助。

关于ios - uitableview 删除 iOS 中的按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34013652/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com