在自定义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);
CGContextStrokePath(cont);
}
@end
@implementation WTCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
TableViewCellBackgroundView *backgroundView = [[TableViewCellBackgroundView alloc] initWithFrame:CGRectZero];
[self setBackgroundView:backgroundView];
}
return self;
}
然后设置分割线的风格UITableViewCellSeparatorStyleNone
UITableViewCellSeparatorStyself.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
至于虚线怎么设置详见
http://blog.youkuaiyun.com/zhangao0086/article/details/7234859