无法在iOS中设置CALayer背景图像

时间:2013-12-27 09:12:14

标签: ios objective-c calayer

我无法设置CALayer的背景图片。我尽力了。 这就是我试图设置背景图像的方式。

-(void)addPlane{

CGSize planeSize = CGSizeMake(350, 200);


CALayer *layer = [CALayer layer];

layer.frame = CGRectMake(480/2 - planeSize.width/2, 320/2 - planeSize.height/2 -20, planeSize.width, planeSize.height);
layer.anchorPoint = CGPointMake(0.5, 0.5);


layer.borderColor = [[UIColor colorWithWhite:1.0 alpha:0.3]CGColor];
layer.cornerRadius = 10;
layer.borderWidth = 4;
layer.contents = (id)[UIImage imageNamed:@"card9.png"].CGImage;
[transformLayer addSublayer:layer];}

我也使用这行代码来设置CALayer的背景图片。

    [layer setBackgroundColor:[[UIColor colorWithPatternImage:[UIImage imageNamed:@"card9.png"]] CGColor]];

0 个答案:

没有答案