在自定义cell .h文件中添加
#import <UIKit/UIKit.h>
@interface TableViewCellBackgroundView : UIView
@end
@interface WTCell : UITableViewCell
@end
.m文件
#import "WTCell.h"
@implementation TableViewCellBackgroundView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
[self setBackgroundColor:[UIColor whiteColor]];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef cont = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(cont, [UIColor redColor].CGColor);
CGContextSetLineWidth(cont, 1);
CGFloat lengths[] = {2,2};
CGContextSetLineDash(cont, 0, lengths, 2); //画虚线
CGContextBeginPath(cont);
CGContextMoveToPoint(cont, 0.0, rect.size.height - 1); //开始画线
CGContextAddLineToPoint(cont, 320.0, rect.size.height - 1);
CGContextS