iPhone: How do I add layers to UIView's root layer to display an image with the content property?

前端 未结 3 1260
盖世英雄少女心
盖世英雄少女心 2021-02-06 11:03

According to the Mac Dev Center docs, you should be able to set the contents property of a CALayer and have that render automatically. However, I still can\'t get a simple image

3条回答
  •  Happy的楠姐
    2021-02-06 11:35

    You could load the image into a UIImageView, which is decended from UIView and therefore has it's own layer property.

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:frame];
    imgView.image = [UIImage imageNamed:@"mypic.png"];
    
    [[[self view] layer] addSublayer:[imgView layer]];
    [imgView release];
    

提交回复
热议问题