复选框图标未正确显示

时间:2014-11-26 11:18:20

标签: ios uitableview checkbox

我正在制作一个应用程序,其中我正在使用tableview单元格,在uitableview单元格中,我使用复选框形式的按钮。我有两张名为" uncheck.png"和" tick.png"当我点击那个按钮时会显示勾选但是取消选中图像就会消失我想要取消勾选图像上的勾选图像...!i want that tick image slightly  that square image

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *tableviewidentifier = @"cell";
    tablecellTableViewCell *cell= [self.activitiesTableView_ dequeueReusableCellWithIdentifier:tableviewidentifier];

    if(cell==nil)
    {
        cell = [[tablecellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableviewidentifier];
    }

    UILabel *valuedate = (UILabel *)[cell viewWithTag:11];
    UILabel *msg = (UILabel *)[cell viewWithTag:12];
    UILabel *date = (UILabel *)[cell viewWithTag:13];
    UILabel *time = (UILabel *)[cell viewWithTag:14];
    [valuedate setText:@"Demo"];
    [msg  setText:@"How are You?"];
    date.text=@"14/07/2014";
    time.text=@"A 08:16";


    // [cell.textLabel setText:activityModel.userName];
    valuedate.font=[UIFont fontWithName:@"SegoeUI" size:15];
    msg.font=[UIFont fontWithName:@"SegoeUI-light" size:10.0];
    date.font=[UIFont fontWithName:@"SegoeUI-light" size:9];
    time.font=[UIFont fontWithName:@"SegoeUI-light" size:9];



    if ([self.checkimageArray containsObject:[self.lblArray objectAtIndex:indexPath.row]])
    {
         [cell.button setImage:[UIImage imageNamed:@"tick.png"] forState:UIControlStateNormal];

        //[cell.button setImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];

    }
    else
    {
         [cell.button setImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];

    }

    cell.button.tag=indexPath.row;
    [cell.button addTarget:self action:@selector(checkButton:) forControlEvents:UIControlEventTouchUpInside];



    return cell;
}

1 个答案:

答案 0 :(得分:2)

使用

取消选中图像作为背景图像
[cell.button setBackgroundImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];

然后将您的支票图像显示为图像

[cell.button setImage:[UIImage imageNamed:@"tick.png"] forState:UIControlStateNormal];

现在您可以在每次点击时更改按钮的图像,但背景图像将被修复。当选择按钮时,将刻度图像设置为图像,否则将其设置为nil

用此

替换您的代码
[cell.button setBackgroundImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];
[cell.button setImage:nil forState:UIControlStateNormal];

if ([self.checkimageArray containsObject:[self.lblArray objectAtIndex:indexPath.row]])
    {
         [cell.button setImage:[UIImage imageNamed:@"tick.png"] forState:UIControlStateNormal];
    }

这可以解决您的问题enter image description here