Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UITableViewCell中绘制线(不使用drawRect)_Ios_Objective C_Uitableview_Drawrect - Fatal编程技术网

Ios 在UITableViewCell中绘制线(不使用drawRect)

Ios 在UITableViewCell中绘制线(不使用drawRect),ios,objective-c,uitableview,drawrect,Ios,Objective C,Uitableview,Drawrect,我有一个UITableViewCell,我想在其中画一些线(比如说,在距TableCell顶部1/3处画一条2pt线,覆盖整个宽度)。这些行将始终位于tableview单元格中的同一位置 一个简单的解决方案是使用-drawRect方法,该方法将使用CGContextStrokePath来画线。但这似乎有点过头了,因为它每次都会调用drawRect,这是低效的 我认为有一种方法可以以某种方式缓存它,这样所有的tableview单元格在默认情况下都是用行创建的。我能想到的一种方法是创建2pt*2pt

我有一个UITableViewCell,我想在其中画一些线(比如说,在距TableCell顶部1/3处画一条2pt线,覆盖整个宽度)。这些行将始终位于tableview单元格中的同一位置

一个简单的解决方案是使用
-drawRect
方法,该方法将使用
CGContextStrokePath
来画线。但这似乎有点过头了,因为它每次都会调用drawRect,这是低效的


我认为有一种方法可以以某种方式缓存它,这样所有的tableview单元格在默认情况下都是用行创建的。我能想到的一种方法是创建2pt*2pt png文件,并将其添加到tableview单元格顶部的UIImageView中。还有其他方法吗?

你可以只添加一个
UIView
像你的
UITableViewCell
的子视图你可以只添加一个
UIView
像你的
UITableViewCell
的子视图你可以只添加一个
UIView
像你的
UITableViewCell
的子视图你可以只添加一个
UIView
UITableViewCell
的子视图类似,另一个选项是添加
UIView
并设置其背景色。例如:

 UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.bounds.size.width, 2)] autorelease];
 lineView.backgroundColor =  [UIColor grayColor];

 [cell.contentView addSubview:lineView];

另一个选项是,添加
ui视图
,并设置其背景色。例如:

 UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.bounds.size.width, 2)] autorelease];
 lineView.backgroundColor =  [UIColor grayColor];

 [cell.contentView addSubview:lineView];

另一个选项是,添加
ui视图
,并设置其背景色。例如:

 UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.bounds.size.width, 2)] autorelease];
 lineView.backgroundColor =  [UIColor grayColor];

 [cell.contentView addSubview:lineView];

另一个选项是,添加
ui视图
,并设置其背景色。例如:

 UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.bounds.size.width, 2)] autorelease];
 lineView.backgroundColor =  [UIColor grayColor];

 [cell.contentView addSubview:lineView];
试试这个-

将此代码添加到您的
单元格中,只需调整此图像视图的y位置-

UIImageView *seperatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 49, 320, 1)];
seperatedImageView.backgroundColor = [UIColor colorWithRed:201.0/255.0 green:250.0/255.0 blue:152.0/255.0 alpha:1.0];
[cellBackView addSubview:seperatedImageView];
试试这个-

将此代码添加到您的
单元格中,只需调整此图像视图的y位置-

UIImageView *seperatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 49, 320, 1)];
seperatedImageView.backgroundColor = [UIColor colorWithRed:201.0/255.0 green:250.0/255.0 blue:152.0/255.0 alpha:1.0];
[cellBackView addSubview:seperatedImageView];
试试这个-

将此代码添加到您的
单元格中,只需调整此图像视图的y位置-

UIImageView *seperatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 49, 320, 1)];
seperatedImageView.backgroundColor = [UIColor colorWithRed:201.0/255.0 green:250.0/255.0 blue:152.0/255.0 alpha:1.0];
[cellBackView addSubview:seperatedImageView];
试试这个-

将此代码添加到您的
单元格中,只需调整此图像视图的y位置-

UIImageView *seperatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 49, 320, 1)];
seperatedImageView.backgroundColor = [UIColor colorWithRed:201.0/255.0 green:250.0/255.0 blue:152.0/255.0 alpha:1.0];
[cellBackView addSubview:seperatedImageView];

Ofc你也可以在故事板中这样做,所以所有单元格都有它(可重用单元格的性能应该比在代码中手动添加到每个单元格更好)Ofc你也可以在故事板中这样做,所以所有单元格都有它(可重用单元格的性能应该比在代码中手动添加到每个单元格更好)Ofc你也可以在故事板中这样做,所以所有单元格都有它(可重用单元格的性能应该比在代码中手动添加到每个单元格更好)Ofc你也可以在故事板中这样做,所以所有单元格都有它(可重用单元格的性能应该比在代码中手动添加到每个单元格更好)