1、自定义table的cell ,用绘制
//Cell.h
#import <UIKit/UIKit.h>
@interface Cell : UITableViewCell
// 标题
@property(nonatomic, strong) NSString *title;
// 图片
@property(nonatomic, strong) UIImage *image;
// 类型 0:无图片 1:有图片
@property(nonatomic, assign) NSInteger type;
@end
//Cell.m- (void)drawRect:(CGRect)rect{
// 绘制底部的线
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0.722 green:0.600 blue:0.451 alpha:1].CGColor);
CGContextStrokeRect(context, CGRectMake(0, rect.size.height - 0.5, rect.size.width, 0.5));
[[UIColor orangeColor]set];
if (self.type == 0) {
[self.title drawInRect:CGRectMake(15, 0, 100, 50) withFont:[UIFont systemFontOfSize:15] lineBreakMode:NSLineBreakByCharWrapping alignment:NSTextAlignmentLeft];
}else if (self.type == 1){
[self.image drawInRect:CGRectMake(20, 14, 20,20)];
}
}
2、tablecontroller//绘制每个cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//文字
cell.title = @"开启通知";
cell.type = 0;
//图片
UIImage *_image = [UIImage imageNamed:@"qq.png"];
cell.image = _image;
cell.type = 1;
[cell setNeedsDisplay]; //调用 draw() 方法
}整理的实在太匆忙,以后继续补充完整,感谢前辈 ,哈哈哈!