Ios 如何更改已点击的UITableViewCell中的UILabel
我在一个UITableViewCell中添加了7个标签,添加了一个UITapGestureRecognitor,并设置了点击目标操作 我希望所有标签都可以点击,并改变点击标签到另一个背景色Ios 如何更改已点击的UITableViewCell中的UILabel,ios,uitableview,uilabel,uitapgesturerecognizer,Ios,Uitableview,Uilabel,Uitapgesturerecognizer,我在一个UITableViewCell中添加了7个标签,添加了一个UITapGestureRecognitor,并设置了点击目标操作 我希望所有标签都可以点击,并改变点击标签到另一个背景色 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //here I leave out how cell are added to the U
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//here I leave out how cell are added to the UITableView.
self.repeatAll = [[NSMutableArray alloc] initWithObjects:@"MON", @"TUE",@"WED",@"THU",@"FRI",@"SAT",@"SUN", nil];
int x =60;
UILabel *label;
for (int i =0; i<7; i++) {
NSString *theText = [self.repeatAll objectAtIndex:i];
label = [[UILabel alloc] init];
label.text = theText;
label.frame = CGRectMake(x+label.frame.size.width, 30.0f, 30.0f, 20.0f);
x = label.frame.size.width + 5+ x;
label.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_tapLabel:)];
[label addGestureRecognizer:tapGesture];
[cell addSubview:label];
}
}
- (void)_tapLabel:(id)sender {
//something I don't know how to change the target label. change it's backgroundColor
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
//这里我省略了单元格是如何添加到UITableView的。
self.repeatAll=[[NSMutableArray alloc]initWithObjects:@“MON”,“TUE”,“WED”,“THU”,“FRI”,“SAT”,“SUN”,nil];
int x=60;
UILabel*标签;
对于(int i=0;i变化:
_tapLabel:(id)sender
致:
然后通过以下方式获取点击视图:
gesture.view
更新颜色将是:
gesture.view.backgroundColor = [UIColor redColor];
gesture.view.backgroundColor = [UIColor redColor];