gpt4 book ai didi

ios - 复选框图标未正确显示

转载 作者:行者123 更新时间:2023-11-29 12:32:58 25 4
gpt4 key购买 nike

我正在制作一个应用程序,我在其中使用 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;
}

最佳答案

使用取消选中的图像作为背景图像使用

[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

关于ios - 复选框图标未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27147779/

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