关于把图片内容绘制到view中

1、把图片内容绘制到view中需要调用的方法

   原理:见官方文档

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    for (int i = 0; i < [self.imageLayerNameArray count]; i++)
    {
        NSString *imageName =[self.imageLayerNameArray objectAtIndex:i];
             NDLog(@"%@",imageName);
        
        NSString *imagePath = [NDTCacheCustomPath getResourcePath:imageName];
        UIImage *image = [[UIImage alloc]initWithContentsOfFile:imagePath];
        [image drawInRect:rect];
    }
}
2、如果需要重绘,没必要重新创建view,调用

   

-(void)setImageLayerNameArray:(NSMutableArray *)imageLayerNameArray
{
    _imageLayerNameArray = imageLayerNameArray;
    [self setNeedsDisplay];
}
setneedsdisplay方法,原理,见官方文档

你可能感兴趣的:(关于把图片内容绘制到view中)