绘制draw table里面的cell

来源:互联网 发布:源mac地址的作用 编辑:程序博客网 时间:2024/06/16 12:56


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, [UIColorcolorWithRed:0.722green:0.600blue:0.451alpha:1].CGColor);

    CGContextStrokeRect(context, CGRectMake(0, rect.size.height -0.5, rect.size.width,0.5));

    

    [[UIColororangeColor]set];

    if (self.type ==0) {

        

        [self.titledrawInRect:CGRectMake(15,0, 100,50) withFont:[UIFontsystemFontOfSize:15]lineBreakMode:NSLineBreakByCharWrappingalignment:NSTextAlignmentLeft];

    }else if (self.type ==1){

        

        [self.imagedrawInRect:CGRectMake(20,14, 20,20)];

    }

}

2、tablecontroller

//绘制每个cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{        

            //文字

            cell.title = @"开启通知";

            cell.type = 0;

           //图片

             UIImage *_image = [UIImageimageNamed:@"qq.png"];

              cell.image = _image;

              cell.type = 1;

         [cell setNeedsDisplay];  //调用  draw() 方法

}

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

0 0