绘制draw table里面的cell


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() 方法

}

整理的实在太匆忙,以后继续补充完整,感谢前辈 ,哈哈哈!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值