在UITableViewCell.m里寫以下方法唉锌,可遍歷出Action的按鈕,這里直接當(dāng)做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]]) {
//更改左滑標(biāo)簽按鈕樣式
if ([btn.titleLabel.text isEqualToString:@"標(biāo)簽"]) {
[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
并且由于此方法會調(diào)用多次辽狈,導(dǎo)致創(chuàng)建多個label,所以聲明了一個label屬性