作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
表格 View 中心单元格始终像选择器一样突出显示。如果我选择中心单元格,则返回该值。如果我在时间中心点滚动表格,则必须突出显示仅更改的值(如选择器操作)如何做到这一点?此任务的任何示例代码。提前致谢。
- (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;
}
行数是 700、800,像这样。
最佳答案
UITableView
扩展了 UIScrollView
。因此您可以实现以下委托(delegate):
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
您可以在其中检查 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];
}
关于iphone - 如何更改表格 View 中心标签突出显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14580063/
有没有一种方法可以“标记”对象的属性,使它们在反射中“突出”? 例如: class A { int aa, b; string s1, s2; public int AA
我是一名优秀的程序员,十分优秀!