Iphone 如何更改高亮显示的表视图中心标签?
“表视图中心”单元始终像选择器一样高亮显示。如果选择中心单元格,则返回该值。如果我在时间中心点滚动表格,必须突出显示仅更改的值(如选择器操作),如何做到这一点?此任务的任何示例代码。提前谢谢Iphone 如何更改高亮显示的表视图中心标签?,iphone,ios,uitableview,Iphone,Ios,Uitableview,“表视图中心”单元始终像选择器一样高亮显示。如果选择中心单元格,则返回该值。如果我在时间中心点滚动表格,必须突出显示仅更改的值(如选择器操作),如何做到这一点?此任务的任何示例代码。提前谢谢 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell";
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UILabel *modelLabel;
UIButton *modelButton;
modelButton = [UIButton buttonWithType:UIButtonTypeCustom];
modelButton.frame = CGRectMake(0.0, 0.0, LABEL_WIDTH, LABEL_HEIGHT);
modelButton.tag = indexPath.row+100;
[modelButton addTarget:nil action:@selector(modelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[[cell contentView] addSubview:modelButton];
modelLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, LABEL_WIDTH, LABEL_HEIGHT)];
modelLabel.text = [NSString stringWithFormat:@"%@", [[modelArray objectAtIndex:indexPath.row] valueForKey:@"Model"]];
modelLabel.tag = indexPath.row+1000;
modelLabel.backgroundColor = [UIColor clearColor];
modelLabel.textColor = [UIColor grayColor];
modelLabel.alpha = 0.5;
modelLabel.textAlignment = UITextAlignmentCenter;
modelLabel.font = EUROSLITE_FONT(14);
[[cell contentView] addSubview:modelLabel];
}
return cell;
}
行数为700800,如下所示。A
UITableView
extendsUIScrollView
。因此,您可以实现以下委托:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
在那里,您可以检查滚动视图.contentOffset
,并将相应的单元格设置为高亮显示。请注意,这不是中心单元格。您需要在scrollView.contentOffset.y上添加(int)(scrollView.frame.size.height/2)-(int)(cell.frame.size.height/2)
示例(请取消突出显示所有其他单元格):
请粘贴一些代码…无法理解您正试图实现的目标…请查看我编辑的问题。请在屏幕中央放置一个透明颜色的视图。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[[tableView visibleCells] makeObjectsPerformSelector:@selector(setHighlighted:) withObject:[NSNumber numberWithBool:NO]];
CGPoint center = CGPointMake(0, scrollView.contentOffset.y+(int)(scrollView.frame.size.height/2));
NSIndexPath *cellIndexPath = [tableView indexPathForRowAtPoint:center];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:cellIndexPath];
[cell setHighlighted:YES];
}