0
이미지 컨텍스트에서 UIImage를 만들고이를 CALayer의 내용으로 설정하려고합니다. 이미지가 분할되어 여러 CALayers로 확산됩니다. 유일한 문제는 정확히 정렬되지 않는 것입니다. 30 픽셀 정도 오프셋됩니다.CALayer 내에서 배경 맞추기
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
number = 1;
background = [UIImage imageNamed:@"numberBackground.png"];
// draw images
UIGraphicsBeginImageContext(CGSizeMake(background.size.width, background.size.height));
[background drawAtPoint:CGPointMake(0, 0)];
NSString *numberString = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%d", number]];
[[UIColor whiteColor] set];
[numberString drawAtPoint:CGPointMake(0, 0) withFont:[UIFont fontWithName:@"HelveticaNeue" size:128]];
UIImage *front = [UIGraphicsGetImageFromCurrentImageContext() retain];
UIGraphicsEndImageContext();
// top layer
topLayer = [CALayer layer];
[topLayer setContents:(id)front.CGImage];
[topLayer setContentsGravity:@"kCAGravityTop"];
[topLayer setFrame:CGRectMake(0, 0, background.size.width, background.size.height/2)];
[topLayer setAnchorPoint:CGPointMake(0, 1)];
[topLayer setPosition:CGPointMake(0, background.size.height/2)];
[topLayer setMasksToBounds:NO];
[topLayer setBackgroundColor:[UIColor lightGrayColor].CGColor];
[self.layer addSublayer:topLayer];
}
return self;
}
나는 아직 이미지를 게시 할 수있는 충분한 명성 포인트가 있지만 여기 계층이 어떻게 렌더링해야하며 전체 이미지뿐만 아니라, 렌더링 방법은 없습니다 : link text