简单雪碧片
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单雪碧片相关的知识,希望对你有一定的参考价值。
Very simple use of an non-animating spritesheet for ios
-(void) addSpriteImage:(UIImage *) image withContentRect:(CGRect) rect toLayer:(CALayer *) layer { //set image layer.contents = (__bridge id)image.CGImage; //scale contents to fit layer.contentsGravity = kCAGravityResizeAspect; //set contentRect to appropriate place in image layer.contentsRect = rect; } - (void)viewDidLoad { [super viewDidLoad]; UIImage *image = [UIImage imageNamed:@"spritesheet.png"]; [self addSpriteImage:image withContentRect:CGRectMake(0, 0, 0.5, 0.5) toLayer:self.someUIView.layer]; [self addSpriteImage:image withContentRect:CGRectMake(0.5, 0, 0.5, 0.5) toLayer:self.someUIView.layer]; [self addSpriteImage:image withContentRect:CGRectMake(0, 0.5, 0.5, 0.5) toLayer:self.someUIView.layer]; [self addSpriteImage:image withContentRect:CGRectMake(0.5, 0, 0.5, 0.5) toLayer:self.someUIView.layer]; }
以上是关于简单雪碧片的主要内容,如果未能解决你的问题,请参考以下文章