Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4620048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:30:27+00:00 2026-05-22T02:30:27+00:00

Trying to understand the relationship between UIView and CALayer. I read Apple documentation but

  • 0

Trying to understand the relationship between UIView and CALayer. I read Apple documentation but it doesn’t describe in detail the relationship between the two.

  1. Why is it that when I add the background image to view “customViewController.view”, I get the unwanted black color of the image.

  2. And when I add the background image to the layer “customViewController.view.layer”, the black area of the image is gone (which is what I wanted), but the background image is flipped upside down. Why is that?

  3. If I were to add labels/views/buttons/etc. to the view, will the layer’s background image block them because CAlayer is backed by UIView?

  4. When you set the background color of a UIView does it automatically set the background color of the associated layer?

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        customViewController = [[CustomViewController alloc] init];
        customViewController.view.frame = CGRectMake(213, 300, 355, 315);
    
        customViewController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]];
        //  customViewController.view.layer.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]].CGColor;
    
        [self.view addSubview:customViewController.view];
    }
    

Background image in view:

background in view

- (void)viewDidLoad
{
    [super viewDidLoad];
    customViewController = [[CustomViewController alloc] init];
    customViewController.view.frame = CGRectMake(213, 300, 355, 315);

//  customViewController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]];
    customViewController.view.layer.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]].CGColor;

    [self.view addSubview:customViewController.view];
}

Background image in view.layer:

background image in layer

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:30:28+00:00Added an answer on May 22, 2026 at 2:30 am
    1. UIView as created opaque by default. When you set the backgroundColor to a pattern with transparency it is choosing black as the background color. You can set customViewController.view.opaque = NO; to allow the background of the view behind yours to show through.

    2. When you set the backgroundColor of the layer to a pattern with transparency you are bypassing the UIView logic, so the opaqueness of the view is ignored; so also is the the UIView’s transform. CoreGraphics and friends use a coordinate system where the positive y-axis points upwards. UIKit flips this coordinate system. This is why the image appears upside down.

    3. If you add labels/views/buttons/etc. the will appear correctly on top of the layer’s background pattern.

    4. When you set the view’s background color it appears as if the layer’s background color is indeed set. (I have not seen this documented anywhere).

    Essentially the UIKit’s UIView stuff is a high-level interface which ends up rendered onto layers.

    Hope this helps.

    EDIT 5/7/2011

    You can get the image to show the right way up by flipping the layer’s coordinate system BUT you shouldn’t do this to view.layer; UIKit doesn’t expect you to mess with this layer, so if your flip its coordinate system any UIKit drawing will be flipped; you need to use a sublayer.

    So your code would look like this:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        customViewController = [[CustomViewController alloc] init];
        customViewController.view.frame = CGRectMake(213, 300, 355, 315);
    
        CALayer* l = [CALayer layer];
        l.frame = customViewController.bounds;
        CGAffineTransform t = CGAffineTransformMake(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
        l.affineTransform = t;
        l.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage
                                 imageNamed:@"login_background.png"]].CGColor;
        [customViewController.view.layer addSublayer:l];
    
        [self.view addSubview:customViewController.view];
    }
    

    Note: normally when you flip coordinates you include the height. For layers you don’t need to do this. I haven’t dug into why this is so.

    As you can see there is a lot more code involved here and there is no real advantage to doing it this way. I really recommend you stick to the UIKit approach. I only posted the code in response to your curiosity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a Delphi novice, but I'm trying to understand the relationship between TApplication
I am trying to understand some things about jump tables and its relationship between
I am trying understand how multi queries work in mysqli. But I confess that
I am trying to understand the relationship between android.graphics package and SurfaceFlinger . Based
I've been trying to understand how Ruby blocks work, and to do that I've
I'm trying to understand the concepts behind DDD, but I find it hard to
Apologies if I'm missing something really obvious, but I'm trying to understand how to
Trying to understand the Android framework model. I have an application that needs to
I'm trying to understand the difference between OnStart() and the constructor in a ServiceBase
I am trying to understand Double-Array Trie implementation from http://linux.thai.net/~thep/datrie/datrie.html But I do not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.