1圖片處理只拿到圖片的一部分圖片
UIImage *image = [UIImage imageNamed:filename];圖片處理
CGImageRef imageRef = image.CGImage;it
CGRect rect = CGRectMake(origin.x, origin.y ,size.width, size.height);file
//這裏的寬高是相對於圖片的真實大小im
//好比你的圖片是400x400的那麼(0,0,400,400)就是圖片的全尺寸,想取哪一部分就設置相應座標便可co
CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect);block
UIImage *imageRect = [[UIImage alloc] initWithCGImage:imageRefRect];play
2給UIView設置圖片
UIImage *image = [UIImage imageNamed:@"playing"];
_layerView.layer.contents = (__bridge id)image.CGImage;
_layerView.layer.contentsCenter = CGRectMake(0.25, 0.25, 0.5, 0.5);
//一樣能夠設置顯示的圖片範圍
//不過此處略有不一樣,這裏的四個值均爲0-1之間;對應的依然是寫x,y,widt,height