在iPhone中的Linked应用程序中,我注意到他们有一个tableview,看到下面的图片看起来有一个向上的三角形指示。
注意tableview单元格如何有一个向上指向的小三角形,并且是tableview单元格的一部分。
三角形是--- ^ ---图像的一部分。
我在想。你如何使用这个三角形指示器创建一个UITableView,这个效果叫什么?
由于
答案 0 :(得分:5)
这是习惯。
您可以采取两种方法:
将UITableView的分隔符样式设置为none,并将UIImageView添加到UITableViewCell,该UITableViewCell具有分隔线和绘制的三角形。我将设置图像视图单元格的原点为负数等于三角形的高度。您必须在该UIIMageView上将clipsToBounds属性设置为NO,以及单元格的背景视图和单元格本身。
基本上与1的方法相同,但我不会使用UIImageView,而是覆盖背景视图的绘制方法并使用Quartz2D绘制线条。
另外,我不使用LinkedIn应用程序,但是内容区域没有在其他地方重复使用或动画,通过将线条上方和下方的区域与箭头组合到一个TableViewCell中,您可以让生活更轻松,并使用UIImageView或Quartz完全使用分隔符。
答案 1 :(得分:3)
以下是执行此操作的代码,您需要有一个像箭头一样的图像,并将以下代码放在CellForRowAtIndexPath方法中...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *celltype=@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celltype];
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;;
cell.backgroundColor=[UIColor clearColor];
UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
cell.accessoryView =
[[[UIImageView alloc]
initWithImage:indicatorImage]
autorelease];
}
UILabel *dateValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 68, 140,20 )];
dateValueLabel.textColor = [UIColor whiteColor];
dateValueLabel.backgroundColor=[UIColor clearColor];
dateValueLabel.text=[NSString stringWithFormat:@"%@",[[productArray objectAtIndex:indexPath.row]valueForKey:@"PostedDate"]];
dateValueLabel.font=[UIFont systemFontOfSize:14];
dateValueLabel.numberOfLines=3;
dateValueLabel.adjustsFontSizeToFitWidth=YES;
[dateValueLabel setLineBreakMode:UILineBreakModeCharacterWrap];
[cell.contentView addSubview:dateValueLabel];
[dateValueLabel release];
return cell;
}
希望这会对你有帮助。我这样做.........