在UITableViewCell.m里写以下方法,可遍历出Action的按钮,这里直接当做UIButton去处理了
- (void)layoutSubviews{
[super layoutSubviews];
//遍历子视图,找出左滑按钮
for (UIView *subView in self.subviews)
{
if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")])
{
for (UIButton *btn in subView.subviews) {
if ([btn isKindOfClass:[UIButton class]]) {
//更改左滑标签按钮样式
if ([btn.titleLabel.text isEqualToString:@"标签"]) {
[btn setTitle:@"" forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"btn_biaoqian"] forState:UIControlStateNormal];
[btn addSubview:self.addLabel];
[self.addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(0);
make.centerY.equalTo(10);
}];
}else if([btn.titleLabel.text isEqualToString:@"详情"]){
//更改左滑详情按钮样式
[btn setTitle:@"" forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"btn_huadong_xiangqing"] forState:UIControlStateNormal];
[btn addSubview:self.detailLabel];
[self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(0);
make.centerY.equalTo(10);
}];
}
修改btn.titleLabel.frame不起作用,所以我这里采用了自己添加一个label
并且由于此方法会调用多次,导致创建多个label,所以声明了一个label属性